-3
Jurisdiction      Route
------------      -----
Portland           65
Portland           55
Cornelius          75
Cornelius          75
Cornelius          75

如何计算cornelius的路线数量?答案是 1

4

2 回答 2

2

您只需要使用COUNT()DISTINCT

select count(distinct Jurisdiction) total, Jurisdiction
from table1
where Jurisdiction = 'Cornelius'
group by Jurisdiction

请参阅带有演示的 SQL Fiddle

于 2012-10-04T02:20:31.450 回答
0
SELECT COUNT(*) 
FROM your_table 
GROUP BY Jurisdiction, Route 
WHERE Jurisdiction = 'Cornelius'

或者

SELECT COUNT(DISTINCT Route) 
FROM your_table 
GROUP BY Jurisdiction 
WHERE Jurisdiction = 'Cornelius'
于 2012-10-04T02:21:13.957 回答