我正在嘗試使用Mongo進行一些測試,我已經找到了一些更簡單的MySQL查詢Mongo等價物。MongoDB - MySQL SUM(CASE WHEN)等價嗎?
我有這個疑問這是一個有點複雜,我需要幫助...
SELECT DISTINCT dims_user,
COUNT(DISTINCT asset_name) AS asset_count,
COUNT(DISTINCT system_name) AS station_count,
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,
SUM(CASE WHEN details Like '%Print%' then 1 Else 0 end) AS Printed_count
FROM asset_log GROUP BY dims_user;
呃......這不是很好的關係練習......「細節」列中的數據應該標準化 - 對於NoSQL db設計也是如此,column:action =(view | web | thumb | export | print),那麼你只需切換到一個組。 – Rudu
它的一堆日誌文件,我剛剛得到了什麼有32萬條記錄 – rreeves
然後[ETL](http://en.wikipedia.org/wiki/Extract,_transform,_load)它一次(如果它是靜態的 - 或建立一個加載/轉換過程用於重複加載),以便它被標準化。這將大大簡化你想要做的事情。 – Rudu