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
答
最简单的自己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}