0
讓當我使用這個查詢如何瑪吉在mysql中列的值
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;
輸出看起來像考慮這個查詢
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
class_id timespent visitedtimespent
1 2000 NULL
2 4000 NULL
,但我預計今年產量
class_id timespent visitedtimespent
1 2000 10
2 4000 5
我怎麼能做到這一點?
謝謝這兩個答案是有用的,但爲什麼總和不同於案件內部和案件之外,由於按功能分組,所有的任何鏈接都更有幫助 – kumar