sql server - SQL count number of groups -


i have table pallets, items, item quantity:

pallet | item | qty -------------------   1        1     2   1        2     4   2        3     2   2        5     3   3        4     4 

i need find count(pallet), count(item), sum(qty)

count(pallets) | count(items) | sum(qty) ----------------------------------------       3                5           15 

i can sum(qty) , count(item)

select count(0) totalitems, sum(qty) total table 

is there way number of pallets without sub-query?

yes, use distinct

select count(distinct pallet) pallets,        sum(qty) total,         count(0) totalitems  your_table 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -