I want to query how many different accounts are linked to one price.
name | price | acc_no
Allnet Flat S | 14.99 | 1
Allnet Flat XL | 24.99 | 2
Data Flat XL | 14.99 | 2
Data Flat S | 9.99 | 1
Family Flat S | 29.99 | 3
Family Flat XXL| 59.99 | 4
SMS Flat S | 9.99 | 1
My closest solution is a
SELECT price, COUNT(acc_no) FROM "table" GROUP BY price
The problem here is that it shows me two accounts linked to 9.99, although it is the same account number. How can I make it count the same account only once?
Use DISTINCT in the COUNT function:
SELECT price, COUNT(DISTINCT account_no) FROM "table" GROUP BY price
-- ^^^^^^^^
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