我試圖做多個計數在同一列與不同的地方像子句。多個計數在同一列與哪裏像 - MySQL
我已經找出了每個類似子句的基本查詢,但我需要將它們組合起來以產生一個結果。
select system_user, COUNT(details) from asset_log where details like 'Viewed';
select system_user, COUNT(details) from asset_log where details like 'Viewed Web%';
select system_user, COUNT(details) from asset_log where details like 'ThumbView';
select system_user, COUNT(details) from asset_log where details like 'Exported%';
我相信它是可能的,我只是不知道該怎麼做。任何幫助,將不勝感激。
在此先感謝
更新:
就這樣結束了,我的工作
select distinct system_user,
SUM(CASE WHEN details ='viewed' then 1 Else 0 end) AS viewed_count,
SUM(CASE WHEN details Like 'Viewed Web%' then 1 Else 0 end) AS Web_count,
SUM(CASE WHEN details = 'ThumbView' then 1 Else 0 end) AS ThumbView_count,
SUM(CASE WHEN details Like 'Exported%' then 1 Else 0 end) AS Exported_count
from asset_log GROUP BY system_user;
謝謝!
有趣的是,它只產生一個用戶名? – rreeves
哎喲忘了羣 –