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

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -