There is table of numbers containing values [1,1,2,3,7,3,4,2,7] I want to select only duplicates so output set would contain [1,2,3,7] so 4 is filtered out.
I have code that I did like this:
DROP TABLE #tempTable;
SELECT [numbers] as nums, COUNT(*) as cny
INTO #tempTable
FROM [testBase].[dbo].[numbers] group by numbers;
SELECT nums from #tempTable where nums > 1;
Now I would like to know if I can get it without first selecting to #tempTable? Something more like select from select or is it only way I can do it?
The same in one query.
Conditions that are made after GROUP BY should be added to HAVING clause.
SELECT [numbers] as nums, COUNT(*) as cny
FROM [testBase].[dbo].[numbers]
GROUP BY numbers
HAVING COUNT(*) > 1
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다