关于SQLSERVER去掉如何重复值的记录
这个一个在日常工作中所遇到的问题 在此记录一下
dt_user_pay_record表
ID userid time money
1 2 2014-3-2 2
2 2 2015-3-2 33
3 2 2011-9-5 5
4 5 2016-2-2 66
5 5 2015-4-4 77
取出数据
userid time money
2 2015-3-2 33
5 2016-2-2 66
我想取出 userid相同的并且time最大的数据
方案1:
select * from (
select id, user_id, created, pay_money,
ROW_NUMBER() over(partition by user_id order by created desc) seq FROM dt_user_pay_record ) tbl where seq =1
方案2:
select * from dt_user_pay_record t1
where not exists(select 1 from dt_user_pay_record t2
where t1.user_id=t2.user_id and t2.created>t1.created)
关于SQLSERVER去掉如何重复值的记录的更多相关文章
- 去掉list重复值
/** * 去掉list重复值 */ public List<String> removeDuplicate(List<String> list) { HashSet<S ...
- oracle 查某一列有重复值的记录
-- 查找重复记录select names,num from test where rowid != (select max(rowid) from test b ...
- 字符串数组(String []) 去掉重复值的方法
public class Demo { /** * 去掉重复值 */ public static void main(String[] args) { String test = "100, ...
- MYSQL中防止插入重复记录的解决方案(无重复值更新)
说明:一般我们使用MYSQL插入记录时,类似于这样的语句: insert into table_name(email,phone,user_id) values(‘test9@163.com’,’99 ...
- PHP 二维数组去掉重复值并保持原结构
PHP 二维数组去掉重复值并保持原结构 直接上代码,解释很详细 //二维数组去掉重复值 function arrunique($a){ foreach($a[0] as $k => $v){ / ...
- PHP如何去掉多维数组的重复值
1.定义函数 function array_unique_new($arr){ $t = array_map('serialize', $arr);//利用serialize()方法将数组转换为以字符 ...
- [LeetCode] Contains Duplicate III 包含重复值之三
Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...
- [LeetCode] Contains Duplicate II 包含重复值之二
Given an array of integers and an integer k, return true if and only if there are two distinct indic ...
- MySQL 处理插入过程中的主键唯一键重复值办法
200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍在插入数据到表中遇到键重复避免插入重复值的处理方法,主要涉及到I ...
随机推荐
- Master Theorem
Master theorem provides a solution in asymptotic terms to solve time complexity problem of most divi ...
- Java中的native方法
博客引用地址:Java中的native方法 今天花了两个小时把一份关于什么是Native Method的英文文章好好了读了一遍,以下是我依据原文的理解. 一. 什么是Native Method 简单地 ...
- freemarker声明变量
freemarker声明变量 1.使用assign创建和替换变量 (1)新建声明变量的ftl variable.ftl: <html> <head> <meta http ...
- iOS8使用Core Graphics实现渐变效果-Swift基础教程
Core Graphics是一个强大的底层API,在这篇教程中我们主要使用Core Graphics来实现渐变效果,为了简单起见,我们采用线性渐变.线性渐变是从起点到终点颜色进行顺序渐变.教程在iOS ...
- UIColor-Hex-Swift
// // UIColorExtension.swift // HEXColor // // Created by R0CKSTAR on 6/13/14. // Copyright (c) 2014 ...
- LR实战之Discuz开源论坛——安装及简介
想了很久,也许是因为这段时间特别闲,从毕业到现在,我的测试职业生涯也近两年了,发现自己越来越喜欢测试领域,也越来越偏向测试开发了,作为一名专业的测试人员,不得不要学习性能测试,而使用LoadRunne ...
- 设置MySQL数据表主键
设置MySQL数据表主键: 使用“primary key”关键字创建主键数据列.被设置为主键列不允许出现重复的值,很多情况下与“auto_increment”递增数字相结合.如下SQL语句所示: My ...
- error: ‘for’ loop initial declarations are only allowed in
使用gcc,出现如下错误: thread_join.c:7:5: error: 'for' loop initial declarations are only allowed in C99 mode ...
- pl/sql连接远程服务器
1.oracle提供了instantclient,下载instantclient-basic-win32-10.2.0.4.zip,将包解压存放到本地,如:D:\STUDY\instantclient ...
- SQL判断是否存在符合某条件的记录
IF EXISTS ( --判断是否存在合符条件的记录 ) FROM [DCL].[SecurityUser] WHERE [UserAccount] = @UserAccount ) BEGIN - ...