SQL 判断列数据重复,谢谢

SQL 判断列数据重复,谢谢

问题描述:

同一张表,判断A列是否有重复的值,如果有,则判断B列中的时间,取时间最大的一条,怎么写语句?

 if exists (select A from 测试表 group by A having count(A)>1)

select A,max(B) from 测试表 group by A having count(A)>1

http://blog.sina.cn/dpool/blog/s/blog_82b0c72f01016gqg.html?
一些查找,去除重复的方法,你自己扩充到你的要求上吧

最简单的自己union自己,一个select a一个select b
再group

Select B from table where A in (select A from table group by A having count (A)>1)

if exists (select A from table group by A having count(A)>1){select A,max(B) from table group by A having count(A)>1}