目前,我有一个查询类似
,查询写成这样:
SELECT username, exerciseId, frustrated, bored
FROM affecttutor.selfreportfrustration
order by username;
我正在尝试使其看起来像这样
可能会做些什么?谢谢您的宝贵时间!
答案 0 :(得分:1)
您可以尝试使用条件聚合
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