Jump to content

SQL Help - Two group bys


Recommended Posts

Update - Nevermind, worked it out :)



Quick SQL question...  I'm sure this is easy to those in the know!

I'm running a quick query against some tables and receiving the following results:


Business | Site | Staff

Insurance | NCL | Steve
Insurance | NCL | Cath
Insurance | MAN | Bob
Billing | MAN | Sarah
Billing | MAN | Tom
Complaints | MAN | Andy


I want to aggregate this to have the total number of staff rather than the individuals:


Billing | MAN | 2

Complaints | MAN | 1
Insurance | MAN | 1
Insurance | NCL | 2



I've got so far with the query but can't work out how to group both the sites and the staff.  It only works if I simplify to two columns (Site and staff)



staff a,
sites s,
business b

b.bu_id = s.bu_id
and a.site_id = s.site_id

order by b.name, s.name
Edited by MiddleAgeCool
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.