SQL中统计某字段不重复个数
注意:下面的举例适用于ORCLE和MSSQL,不能在Access中使用。
语法
SELECT COUNT(DISTINCT column(s)) FROM table |
举例
With this “Orders” Table:
用的是这张”Orders”表:
Company | OrderNumber |
---|---|
Sega | 3412 |
W3Schools | 2312 |
Trio | 4678 |
W3Schools | 6798 |
举例
SELECT COUNT(Company) FROM Orders |
结果:
4 |
举例
SELECT COUNT(DISTINCT Company) FROM Orders |
结果:
3 |