0
SELECT sum(case when (gender)=1 THEN 1 ELSE 0 END),
GROUP_CONCAT(sum(case when (gender)=2 THEN 1 ELSE 0 END) SEPARATOR ' ') as combine
from family_member_tbl
GROUP BY gender
SELECT sum(case when (gender)=1 THEN 1 ELSE 0 END),
GROUP_CONCAT(sum(case when (gender)=2 THEN 1 ELSE 0 END) SEPARATOR ' ') as combine
from family_member_tbl
GROUP BY gender
不,你不能嵌套這樣的分組功能。寧可拿到總額,然後group_concat()
像
select sum_1, sum_2, group_concat(sum_2) as combine
from (
SELECT gender,
sum(case when gender = 1 THEN 1 ELSE 0 END) as sum_1,
sum(case when gender = 2 THEN 1 ELSE 0 END) as sum_2
from family_member_tbl
GROUP BY gender) xxx
group by gender;
相同的行嗎?對於所有性別,只需刪除GROUP BY。 – jarlh
我不明白總結是否性別(即,如果性別= 2,那麼一個事件計爲兩個)。計數會更好嗎?如果是這樣,那麼@拉胡爾的解決方案可以相應地進行調整。 – RMathis
請提供原始數據樣本和預期結果,這將有助於很多 – Alex