I need to generate a report with the top 3 zip codes by Location. My tables are Location, Customer, and Address.
I have a Select statement like this:
Select l.name, a.zip, count(a.zip) as count
From location l
inner join customer c on c.locationid = location.id
inner join address a on a.customerid = c.id
group by l.name, a.zip
order by l.name, count desc
this returns all the zip codes per location (and a count of each) but I would like to just return the top 3 zips per location.
I am looking for the results to look like this:
Boulder 80304 258
Boulder 80301 190
Boulder 80302 172
Bridgewater 08805 205
Bridgewater 07920 99
Bridgewater 08876 98
Broomfield 80020 796
Broomfield 80027 207
Broomfield 80021 144
...
Any ideas?
I have a Select statement like this:
Select l.name, a.zip, count(a.zip) as count
From location l
inner join customer c on c.locationid = location.id
inner join address a on a.customerid = c.id
group by l.name, a.zip
order by l.name, count desc
this returns all the zip codes per location (and a count of each) but I would like to just return the top 3 zips per location.
I am looking for the results to look like this:
Boulder 80304 258
Boulder 80301 190
Boulder 80302 172
Bridgewater 08805 205
Bridgewater 07920 99
Bridgewater 08876 98
Broomfield 80020 796
Broomfield 80027 207
Broomfield 80021 144
...
Any ideas?