mongodb分組統計
從使用過程感受來看,MongoDB的語法還是很強大的,但是確實也很有限制
限制一:
我們經常要group by 多個欄位。但是MongoDB沒有找到方案
mysql的巢狀查詢沒有找到MongoDB的替代方案比如:select count(*) from (select date from table group by date)
$data = [
['$match' =>
[
'channel_attribute' =>
[
'$in' => explode(",", $where["channel_attribute"]),
]
],
],
['$group' =>
[
'_id' => ['$create_date'],
'channel_id' =>
[
'$first' => '$channel_id'
],
'create_date' =>
[
'$first' => '$create_date'
],
'sum_wx_user_num' =>
[
'$sum' => '$wx_user_num'
],
'phone_user_num' =>
[
'$sum' => '$phone_user_num'
],
'trade_sum_fee' =>
[
'$sum' => '$trade_sum_fee'
],
'anticipated_income' =>
[
'$sum' => '$anticipated_income'
]
]
],
// ['$limit' => $page_num],
// ['$skip' => 0],
];
// 過濾時間
if(isset($where["from_date"]) && $where["from_date"] != ''){
$date['$gte'] = $where["from_date"];
}
if(isset($where["to_date"]) && $where["to_date"] != ''){
$date['$lte'] = $where["to_date"];
}
if(isset($date)) $data[0]['$match']['create_date'] = $date;
// 過濾計數級別
if(isset($where["channel_depth"]) && $where["channel_depth"] != ''){
$depth['$lte'] = $where["channel_depth"];
$data[0]['$match']['channel_depth'] = $depth;
}
$cursor = $this->mongo->aggregate($data);
print_r(iterator_to_array($cursor));exit;
相關文章
- MONGODB03 - 分組計數/分組去重計數(基於 spring-data-mongodb)MongoDBSpring
- [Shell] awk 統計分組資料
- 資料庫分類統計、分組查詢資料庫
- MongoDB 如何實現巢狀子文件分組MongoDB巢狀
- mysql加強(3)~分組(統計)查詢MySql
- Oracle按時間分組統計的sqlOracleSQL
- 查詢統計SQL分組求和使用小技巧SQL
- 《MySQL 入門教程》第 12 篇 分組統計MySql
- Oracle 分組彙總統計函式的使用Oracle函式
- 《卸甲筆記》-分組統計查詢對比筆記
- python寫的簡單分組統計指令碼Python指令碼
- python資料統計,分組的一些小技巧Python
- Python的pandas的Dataframe使用groupby分組並求每組的統計值Python
- 按 host 分組統計檢視 | 全方位認識 sys 系統庫
- 按 file 分組統計檢視 | 全方位認識 sys 系統庫
- 按 user 分組統計檢視|全方位認識 sys 系統庫
- sql 語言 groupBy 分組統計時間段解決方案SQL
- Elasticsearch 查詢結果分組統計,聚合檢索(group by stats)Elasticsearch
- ES 24 - 如何通過Elasticsearch進行聚合檢索 (分組統計)Elasticsearch
- 函式及分組統計和資料庫備份,恢復函式資料庫
- sql分組查詢語句--行內分組(非聚合分組)SQL
- MongoDB中如何使用統計count()方法?MongoDB
- 統計資料按日期分組,沒有的天補零,什麼辦
- centos下對檔案某些特定字串分組統計出現次數CentOS字串
- MS SQL Server常見問題 -- 分組 去重複 查詢 統計SQLServer
- mongodb怎樣分庫MongoDB
- mongodb怎麼統計不重複數量?MongoDB
- python 系統函式呼叫sed分組Python函式
- SQL分組SQL
- mongodb的讀寫分離MongoDB
- 【SQL*Plus】使用BREAK和COMPUTE在SQL*Plus中得到分組統計結果SQL
- 分組校驗
- 計組讀記 1:系統概述
- MongoDB 為系統新增MongoDB服務MongoDB
- BIRT 統計圖中怎麼根據引數實現 X 軸動態分組
- mongodb如何不區分大小寫MongoDB
- 【五分鐘瞭解MongoDB】Change Stream 和MongoDB 4.xMongoDB
- SQL 如何計算每個分組的中位數SQL