我正在尝试计算表中有一个区域的行数,我该如何实现这一点,我目前已经编写了这个查询,
SELECT DISTINCT area
FROM cv
WHERE status = 'SHOW'
AND is_complete = 'TRUE'
ORDER BY area ASC
此查询当前返回
area
------------------
West Yorkshire
Lanchashire
我想要的是,
area Number
------------------------
West Yorkshire 19000
Lancashire 7000
答案 0 :(得分:4)
select area, count(*)
from cv
where status = 'SHOW'
and is_complete = 'TRUE'
group by area
答案 1 :(得分:3)
SELECT area, COUNT(area)
FROM cv
WHERE status = 'SHOW'
AND is_complete = 'TRUE'
GROUP BY area
区域计数将仅计算非空值
答案 2 :(得分:1)
SELECT area, COUNT(area)
FROM cv
WHERE status = 'SHOW'
AND is_complete = 'TRUE'
AND area IS NOT NULL
GROUP BY area
答案 3 :(得分:0)
sql distinct将仅列出表中的不同值,原始查询将需要具有count()和group by:
SELECT DISTINCT area, count(*)
FROM cv
.....
group by area
或者,Red Filer和gkrogers的答案也很好。