关于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 ...
随机推荐
- UESTC_Can You Help God Wu CDOJ 582
There is a boy named God Wu in UESTC ACM team. One day he is asked to finish a task. The task is tha ...
- 关于随机数字K线极值的统计结果
如果有组随机数字,如数字彩票.我们对号码进行平均二分后,统计期出现的结果分布,对结果分布进行K线累加,得到一条折线. 这条折线的顶点和底点的统计上服从以下规则: 令总期数为N,统计区间为M,则在N期内 ...
- tangible T4 Editor 2.2.3 for VS2010 / VS2012 / VS2013 Preview
tangible T4 Editor 2.2.3 for VS2010 / VS2012 / VS2013 Preview angible T4 Editor 2.2.3 plus UML model ...
- poj 2411 Mondriaan's Dream(状态压缩dp)
Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...
- 【温故而知新】Tcp/Ip协议——总览
Tcp/Ip协议 一.概念 “三网”:即电信网络.有线电视网络和计算机网络 标准(Standards) 描述了协议的规定,设定了最简的性能集. 协议(Protocol) 网络设备用于交换信息的系列规则 ...
- Java单例模式的线程安全问题
单例模式有两种书写模式:饿汉式和懒汉式. 1.饿汉式 class Single{ private final static Single s = new Single(); private Singl ...
- MySql优化-你的SQL命中索引了吗
在项目开发中SQL是必不可少的,表索也一样.这些SQL的运行性能不知道吗?有多少是命中了索引的?命中哪个索引?索引中有哪个是无效索引?这些无效索引是否会影响系统的性能?带着这些问题我们一起来学习一下. ...
- dir_colors linux颜色配置
在控制台下,用ls,就会发现,shell将不同类型的文件项目显示为不同的颜色.者可以提高效率,不用ls -l便能大概的把各个文件的类型情况了解一下. 你有没有想过更改这个着色配置呢? 其实,在/etc ...
- html中的表格 bootstrap-table
1 bootstrap-table 官网: http://bootstrap-table.wenzhixin.net.cn/ 2
- Direct2D 几何计算和几何变幻
D2D不仅可以绘制,还可以对多个几何图形对象进行空间运算.这功能应该在GIS界比较吃香. 这些计算包括: 合并几何对象,可以设置求交还是求并,CombineWithGeometry 边界,加宽边界,查 ...