以下是我要解决的问题(图片链接) -
我坚持创建动态标头。我在哪里的基本要点是。
SELECT
CASE
WHEN Color = 'Blue' THEN COUNT(ID)
END AS 'no_of_blue'
CASE
WHEN Color = 'Red' THEN COUNT(ID)
END AS 'no_of_red'
CASE
WHEN Color = 'Green' THEN COUNT(ID)
END AS 'no_of_green'
答案 0 :(得分:0)
SELECT SUM(CASE WHEN color = 'Blue'
THEN 1
ELSE 0
END) 'no_of_blue',
SUM(CASE WHEN color = 'Red'
THEN 1
ELSE 0
END) 'no_of_red',
SUM(CASE WHEN color = 'Green'
THEN 1
ELSE 0
END) 'no_of_green'
或PIVOT也可能有用