关于SQLSERVER去掉如何重复值的记录
2016-06-12 10:34
302 查看
这个一个在日常工作中所遇到的问题 在此记录一下
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)
相关文章推荐
- MySQL5.6的my.ini配置
- 玩转mongodb(七):索引,速度的引领(全文索引、地理空间索引)
- 数据库5 索引 动态哈希(Dynamic Hashing)
- Mysql字段类型——字符类型
- 从分布式数据库结构入手讲解其前世今生
- spark-sql
- Memcached是什么?【小强性能培训学员作品】
- 数据库连接池的好处
- MongoDB的golang驱动安装 + 首次调用Mongo Command。
- [PHP][REDIS]phpredis 'RedisException' with message 'read error on connection'
- memcache缓冲雪崩现象
- 推荐数据库、Web、Net、架构的PDF数据,书不在多,在看!
- oracle——多表查询
- 解决 Native method not found: com.baidu.platform.comjni.map.commonmemcache.JNICommonMemCache.Create:()
- mysql 数据库备份方案及策略
- SQL分页存储过程实例
- 【译】MySQL – The Error Log
- 分页技术原理与实现之Java+Oracle代码实现分页(二)
- MySQL数据库优化(七)——MySQL主从复制
- 我的第一个extjs desktop + jsp +mysql实战练习项目