[英]Count the number of the record of this query - a count for distinct pairs before
This is my T-SQL query code:这是我的 T-SQL 查询代码:
SELECT DISTINCT
StateProvince, City
FROM
adventureworks.SalesLT.Address
WHERE
CountryRegion LIKE 'Canada'
AND StateProvince != 'Quebec'
ORDER BY
StateProvince, City
I tried to use this, but it did not work out我尝试使用它,但没有成功
SELECT
COUNT (DISTINCT StateProvince, City) OVER (PARTITION BY )
FROM
adventureworks.SalesLT.Address
WHERE
CountryRegion LIKE 'Canada'
AND StateProvince != 'Quebec'
ORDER BY
StateProvince, City
that is better to use GROUP BY in T-SQL for aggregate functions like COUNT, SUM and so on.对于 COUNT、SUM 等聚合函数,最好在 T-SQL 中使用 GROUP BY。
SELECT COUNT(*)
From adventureworks.SalesLT.Address
WHERE CountryRegion LIKE 'Canada' AND StateProvince != 'Quebec'
GROUP BY City, StateProvince
ORDER BY StateProvince, City
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.