name status
a win
a run
a run
b run
b win
b win
c run
c run
c run
d run
d run
e NA
e run
e win
f NA
f NA
f NA
在mysql
在这里,我需要计算跑步次数,并且赢球和NA也不相同
有人可以帮我吗?
期望的输出
WIN 3
RUN 2
NA 1
尝试过的查询
SELECT a
FROM data
GROUP BY a
HAVING ( COUNT(*) > 1 )
答案 0 :(得分:0)
尝试使用条件聚合:
SELECT
name,
COUNT(CASE WHEN status = 'win' THEN 1 END) AS WIN,
COUNT(CASE WHEN status = 'run' THEN 1 END) AS run,
COUNT(CASE WHEN status = 'NA' THEN 1 END) AS NA
FROM yourTable
GROUP BY
name;