我有如下表:Mysql的計數發言和小組
id user type 11 4 1 12 4 1 13 4 1 14 5 2
那麼我就需要計數和訂單的用戶,並鍵入如下:
user type1 type2 4 3 0 5 0 1
,我提出的SQL語句只是導致這:
user type1 type2 4 3 1 5 3 1
有人能幫助我嗎?
我有如下表:Mysql的計數發言和小組
id user type 11 4 1 12 4 1 13 4 1 14 5 2
那麼我就需要計數和訂單的用戶,並鍵入如下:
user type1 type2 4 3 0 5 0 1
,我提出的SQL語句只是導致這:
user type1 type2 4 3 1 5 3 1
有人能幫助我嗎?
與此類似這樣試試:
SELECT id, user, type, COUNT(type) as count
FROM table_name
GROUP BY user
而且看到一些代碼將是有益的。
這應該工作
select user, sum(if(type=1,1,0)) as type1, sum(if(type=2,1,0)) as type2 from table_name group by user
它工作正常。謝謝。 – user3626648
你取得的成績,到目前爲止,任何代碼? – Vickel
用戶4是否始終輸入1? – Strawberry