目前我有一个看起来像这样的查询
查询是这样写的:
SELECT username, exerciseId, frustrated, bored
FROM affecttutor.selfreportfrustration
order by username;
我正在努力让它看起来像这样
可能的方法是什么?感谢您的宝贵时间!
最佳答案
您可以尝试使用条件聚合
select
username,exerciseid,
count(case when frustrated='Y' then 1 end) as frustrated,
count(case when frustrated<>'Y' then 1 end) as notfrustrated,
count(case when bored<>'N' then 1 end) as bored ,
count(case when bored='N' then 1 end) as notbored
from affecttutor.selfreportfrustration
group by username,exerciseid
关于MYSQL 合并、计数和分离具有相同 id 但不同值的行的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53315761/