sql - MSSQL: Select rows with more than 2 occurrences in another table -
basically need list of campaigntitles have more 2 occurrences in staffongrade , list campaigntitle, staffno have grade rating higher 2
workson table:
campaigntitle | staffno -------------------|-------- adventure world | 11 air canada | 11 carnival cruises | 3 carnival cruises | 8 carnival cruises | 9 flight centre | 7 flight centre | 10 harveyworld travel | 4 last minute | 4 princess cruises | 3 princess cruises | 5 princess cruises | 6 princess cruises | 7 princess cruises | 11 travelscene | 10 valuetours aust | 3 virgin australia | 10
staffongrade table:
grade | staffno ------|-------- 1 | 2 2 | 11 3 | 3 3 | 6 3 | 7 4 | 4 4 | 8 4 | 10 5 | 5 5 | 9
the following 2 queries achieve individual parts, need returned 1 query set of results.
select campaigntitle, count (campaigntitle) [count] workson group campaigntitle having count(campaigntitle) >2 select staffno, grade staffongrade grade > 2
hope makes sense!
select campaigntitle, staffno, count (campaigntitle) [count] workson staffno in (select staffno staffongrade grade > 2) group campaigntitle having count(campaigntitle) >2
Comments
Post a Comment