这个一个在日常工作中所遇到的问题 在此记录一下

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去掉如何重复值的记录的更多相关文章

  1. 去掉list重复值

    /** * 去掉list重复值 */ public List<String> removeDuplicate(List<String> list) { HashSet<S ...

  2. oracle 查某一列有重复值的记录

    -- 查找重复记录select names,num from test where rowid != (select max(rowid)                  from test b   ...

  3. 字符串数组(String []) 去掉重复值的方法

    public class Demo { /** * 去掉重复值 */ public static void main(String[] args) { String test = "100, ...

  4. MYSQL中防止插入重复记录的解决方案(无重复值更新)

    说明:一般我们使用MYSQL插入记录时,类似于这样的语句: insert into table_name(email,phone,user_id) values(‘test9@163.com’,’99 ...

  5. PHP 二维数组去掉重复值并保持原结构

    PHP 二维数组去掉重复值并保持原结构 直接上代码,解释很详细 //二维数组去掉重复值 function arrunique($a){ foreach($a[0] as $k => $v){ / ...

  6. PHP如何去掉多维数组的重复值

    1.定义函数 function array_unique_new($arr){ $t = array_map('serialize', $arr);//利用serialize()方法将数组转换为以字符 ...

  7. [LeetCode] Contains Duplicate III 包含重复值之三

    Given an array of integers, find out whether there are two distinct indices i and j in the array suc ...

  8. [LeetCode] Contains Duplicate II 包含重复值之二

    Given an array of integers and an integer k, return true if and only if there are two distinct indic ...

  9. MySQL 处理插入过程中的主键唯一键重复值办法

    200 ? "200px" : this.width)!important;} --> 介绍 本篇文章主要介绍在插入数据到表中遇到键重复避免插入重复值的处理方法,主要涉及到I ...

随机推荐

  1. WebBot - Build Web Apps as Easily as Native Ones - Home

    Python-based Template Packages Python-based Template Packages WebBot - Build Web Apps as Easily as N ...

  2. Elasticsearch 安装与集群配置

    一.软件版本 操作系统:CentOS-6.5-x86_64 ES版本:5.0 主机:192.168.63.246 主机: 192.168.63.242 二.部署环境规划:   1. 需求:jdk版本: ...

  3. hdu 5491 The Next(暴力枚举)

    Problem Description Let L denote the number of 1s in integer D’s binary representation. Given two in ...

  4. 蚂蚁的难题(二)首尾相连数组的最大子数组和(DP)

    蚂蚁的难题(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:3 描述 下雨了,下雨了,蚂蚁搬家了. 已知有n种食材需要搬走,这些食材从1到n依次排成了一个圈.小蚂蚁对每种食材 ...

  5. 在web应用程序中使用MemcachedClient

    本文来自:http://www.cnblogs.com/yukaizhao/archive/2008/11/10/memcached_client_usage.html 一. 背景: 在大访问量的we ...

  6. svn 清理失败 (cleanup 失败) 的解决方法

    svn 清理失败 (clean up 失败) 的解决方法 參考:http://www.tuicool.com/articles/biy6na 解决方法: step1: 到 sqlite官网 (http ...

  7. wpf动画概述

    http://msdn.microsoft.com/zh-cn/library/vstudio/ms752312(v=vs.100).aspx Windows Presentation Foundat ...

  8. PHP反射ReflectionClass、ReflectionMethod 入门教程

    PHP反射ReflectionClass.ReflectionMethod 入门教程 作者:SNSGOU 发布于:2014-03-16 16:44:00  分类:PHP   浏览(6145) PHP5 ...

  9. PCL库配置出现的问题(WIN10+VS2013)

    边看电影边配终于配好了,中间出现了一些问题,在网上很难搜到,可能每个人都碰到的不同.摸索了一会终于都解决了,记录在这里,免得又碰到. PCL是什么东西就不在此介绍了. 主要是参考这篇博客做得,不过我后 ...

  10. stagefright框架(六)-Audio Playback的流程

    到目前为止,我们都只着重在video处理的部分,对于audio却只字未提.这篇文章将会开始audio处理的流程. Stagefright中关于audio的部分是交由AudioPlayer来处理,它是在 ...