有没有办法将其浓缩为2列? COUNT(列)

时间:2012-10-05 02:42:52

标签: select count where

SELECT COUNT(title) AS SH
FROM movies
where genre = 'SH';

SELECT COUNT(title) AS CH
FROM movies
where genre = 'CH';

SELECT COUNT(title) AS ADV
FROM movies
where genre = 'ADV';

SELECT COUNT(title) AS COM
FROM movies
where genre = 'COM';

SELECT COUNT(title) AS DR
FROM movies
where genre = 'DR';

SELECT COUNT(title) AS SF
FROM movies
where genre = 'SF'

2 个答案:

答案 0 :(得分:2)

SELECT count(*), genre
FROM movies
GROUP BY genre;

答案 1 :(得分:1)

你的意思是这样吗?

SELECT类型,COUNT(标题) 来自电影 GROUP BY流派