Question
sql sum question
I need to produce a CF report only showing the top five
suppliers, plus other information.
I count each supplier, with group by, then sum the count, with group by, to get the total occurrances of each supplier. My query/subquery is something like this :
select sum(supplierCount) as totalCount, supplier
from
(
select count(supplier) as suppliercount, supplier
from table
group by supplier
) as a
group by supplier
order by supplier
This appears to work and gives me the total occurrances of each supplier. I can then select the top 5. Howver, when I start including the other columns, the count/sum does not seem to work anymore and becomes 1 for each supplier. I even tried usign QofQ and that did not work.
How can I write the query to give me the total number of occurrances of each supplier, in addition to having the other columns on the report ?
I count each supplier, with group by, then sum the count, with group by, to get the total occurrances of each supplier. My query/subquery is something like this :
select sum(supplierCount) as totalCount, supplier
from
(
select count(supplier) as suppliercount, supplier
from table
group by supplier
) as a
group by supplier
order by supplier
This appears to work and gives me the total occurrances of each supplier. I can then select the top 5. Howver, when I start including the other columns, the count/sum does not seem to work anymore and becomes 1 for each supplier. I even tried usign QofQ and that did not work.
How can I write the query to give me the total number of occurrances of each supplier, in addition to having the other columns on the report ?