I have a table with pallets, items, item quantity:
pallet | item | qty
-------------------
1 1 2
1 2 4
2 3 2
2 5 3
3 4 4
I need to find count(pallet), count(item), sum(qty)
count(pallets) | count(items) | sum(qty)
----------------------------------------
3 5 15
I can get the sum(qty) and count(item) with
select count(0) as totalItems, sum(qty) as total from table
Is there a way to get the number of pallets without a sub-query?
Yes, use DISTINCT
select count(distinct pallet) as pallets,
sum(qty) as total,
count(*) as totalItems
from your_table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With