您好,我有一個表如下:MySQL的總計數muliple列
用戶表
id val1 val2 val3
1 2 3 2
2 0 0 1
我想知道如何從列計數值VAL1,VAL2,VAL3其中id = 1 ?這意味着 爲id = 1
總數是7和id = 2
總數是1最讓例子計數整個列所有ids.My解決方案如下似乎沒有得到首選結果
select count(*) as tot
from (
select val1 as total from user
where id=1
union
select val2 as total from user
where id=1
union
select val3 as total from user
where id=1
) as x
感謝您的幫助。
@andrian謝謝你的朋友你的解決方案也可以工作! – d3bug3r