我需要在SQL Server的表中找到具有重复订单号的行。
例如SELECT *显示:
myapp.config(['$mdThemingProvider',function($mdThemingProvider){
$mdThemingProvider.theme('default')
.primaryPalette('rgb(x,y,z)');
}]);
我想要
No
-----
5001
5002
5003
5003
5003
5004
5005
5006
5006
是否可以编写查询来执行此操作?
答案 0 :(得分:0)
虽然这个问题在SO上被回答了数千次,但请使用GROUP BY
+ HAVING
:
SELECT No
FROM dbo.tablename
Group By No
Having Count(*) > 1
答案 1 :(得分:0)
SELECT S.No
FROM [dbo].[Shows] S
INNER JOIN (
SELECT [No]
FROM [dbo].[Shows]
GROUP BY [No]
HAVING COUNT(*) > 1
) J
ON S.No = J.No
答案 2 :(得分:0)
您可以使用COUNT() OVER()
获取每No
行的计数,并在外部查询中过滤掉所有不重复的行:
SELECT [No]
FROM (
SELECT [No], COUNT(*) OVER (PARTITION BY [No]) AS cnt
FROM mytable ) t
WHERE cnt > 1