让我们考虑这个查询
select class_id,case when event_id=2 then sum(time_spent) end as timespent ,case when event_id=3 then sum(timespent) end as visitedtimespent from class group by class_id,event_id;
输出看起来像
class_id timespent visitedtimespent
1 2000 NULL
1 NULL 10
2 4000 NULL
2 NULL 5
当我使用这个查询
select class_id,case when event_id=2 then sum(time_spent) end as timespent ,case when event_id=3 then sum(time_spent) end as timespent from class group by class_id;
输出看起来像
class_id timespent visitedtimespent
1 2000 NULL
2 4000 NULL
但我期望这个输出
class_id timespent visitedtimespent
1 2000 10
2 4000 5
我怎样才能做到这一点?