Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 rowcount and grouping

Author  Topic 

lwalker
Starting Member

1 Post

Posted - 2003-02-06 : 16:00:25
I want to take the following query and only display the information for a specific column where an instance of that information occurs at least 3 times.

SELECT id, product_code
FROM activity
WHERE activity_type = 'meeting' AND product_code LIKE 'p%' AND
id IN
(SELECT st_id
FROM AUTOTECH_REGISTRATIONS) AND
transaction_date BETWEEN '01/01/2002' AND
'12/31/2002'
ORDER BY id

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-06 : 16:11:27
SELECT id, product_code, Count(*)
FROM activity
WHERE activity_type = 'meeting' AND product_code LIKE 'p%'
AND id IN (SELECT st_id FROM AUTOTECH_REGISTRATIONS)
AND transaction_date BETWEEN '01/01/2002' AND '12/31/2002'
GROUP BY id, product_code
HAVING (COUNT(*) > 3)
ORDER BY id

Go to Top of Page
   

- Advertisement -