我能够按匹配数计算项目。我问我是否可以在一个查询中执行许多计数?
db.collection.aggregate([
{
$match: { "TYPE": { $in: ["a", "b", "c"] }, PartnerId: "2021" }
},
{
$count: "Control"
}
])
SELECT
SUM(CASE WHEN CD_EVENTO IN('a', 'b', 'c') THEN 1 ELSE 0 END) AS Tipo1,
SUM(CASE WHEN CD_EVENTO IN('d', 'e', 'f') THEN 1 ELSE 0 END) AS Tipo2,
SUM(CASE WHEN CD_EVENTO IN('g', 'h', 'i') THEN 1 ELSE 0 END) AS Tipo3,
FROM TABLE
我可以像在SQL上那样在单个查询中进行操作吗? (我能够在MSSQL上做到这一点。)