Question

Locked

Nested Query - Count

By MemphisMaven ·
How can I do the following in one nested query. I am using SQL Server 2005. Thanks

SELECT Program, PRC_PROGRAM_ID
INTO #TEMP
FROM tblPayment
GROUP BY PROGRAM, PRC_PROGRAM_ID

SELECT Program, COUNT(*) FROM #TEMP GROUP BY Program HAVING COUNT(*)>1
DROP TABLE #TEMP

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Something like this

by Tony Hopkinson In reply to Nested Query - Count

Select Program,Count(*) From
(SELECT Program, PRC_PROGRAM_ID
FROM tblPayment
GROUP BY PROGRAM, PRC_PROGRAM_ID) pgm
HAVING COUNT(*)>1

or even

Select * From
(Select Program,Count(*) as instances From
(SELECT Program, PRC_PROGRAM_ID
FROM tblPayment
GROUP BY PROGRAM, PRC_PROGRAM_ID) pgm) npgm
Where instances > 1

pgm & npgm are aliases for the query in the parentheses.

Back to Networks Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums