I want to create a query that satisfies these criteria:
This is what I've got so far:
SELECT TOP(3) COUNT(DISTINCT column_name) AS some_alias FROM tablename
GROUP BY ~ ORDER BY count(*) asc
What is wrong with my query?
use distinct value inside subquery then use count in select query like below.
SELECT columnName,
COUNT(col1) AS Col,
COUNT(col2) AS col2
FROM
(
SELECT DISTINCT
columnName,
Col1,
col2
FROM table
)
GROUP BY columnName;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.