TABLE quotation
id clientid
1 25
2 25
3 25
4 25
5 26
How can I query how many different clients exist in TABLE quotation
? I don't want duplicate entries to be counted more than once.
I need the answer to be 2
, in 1 row, because the only non-duplicated entries are (25
, 26
).
To count distinct values, you can use distinct in aggregate function count(). The result i3 tells that we have 3 distinct values in the table.
We can use SQL Count Function to return the number of rows in the specified condition. The syntax of the SQL COUNT function: COUNT ([ALL | DISTINCT] expression); By default, SQL Server Count Function uses All keyword.
Answer: COUNT function is an aggregate function that can be used in 3 ways. COUNT(*) – This would COUNT all the rows returned by the SELECT QUERY.
The COUNT DISTINCT function returns the number of unique values in the column or expression, as the following example shows. SELECT COUNT (DISTINCT item_num) FROM items; If the COUNT DISTINCT function encounters NULL values, it ignores them unless every value in the specified column is NULL.
select count(distinct clientid) from quotation
read more
I find a way out
SELECT COUNT(*) as total FROM (SELECT COUNT(*) FROM quotation GROUP BY
clientid) t1
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