在SQL中,经常会出现某个字段重复出现N次以上的方法,经常需要考虑很久,接下来我把SQL Server的语句公式写下来,以后直接套用就行,可以剩下不少时间。
select * from 表 where 字段1 in( select 字段1 from 表 group by 字段1 having count(1)>N) order by 字段
下面我可以写一个例子,如下:
select * from NewRetail_Trade where Trade_FinishedTime IS NOT NULL and Trade_OrderID in( select Trade_OrderID from NewRetail_Trade where Trade_FinishedTime IS NOT NULL group by Trade_OrderID having count(1)>1) order by Trade_OrderID
希望对大家有所帮助