我有類似表:迷茫中集團通過在MySQL
user_id | action
1 a1
2 a1
1 a1
3 a1
2 a1
1 a2
2 a2
我必須找出誰已經用行動數量和用戶A1的數量做動作A1,用戶羣數量。
例如,在上表中,輸出應該是:
num_users num_action_a1
1 (user: 3) 1
2 (user: 1,2) 2
我嘗試下面的查詢
select user_id, count(user_id) from table where action = 'a1' group by user_id
我必須通過使用嵌套組?
你嘗試什麼查詢? – Gunaseelan
從表中選擇user_id,count(user_id)其中action ='a1'group by user_id - 我對使用2組感到困惑 –
請檢查http://stackoverflow.com/questions/1841426/is-it-possible-多個列使用mysql – Gunaseelan