我对 SQL 有点陌生。我需要编写一个查询,使用 MessageTypeId 过滤器从 Cosmos 数据库容器返回两种类型的文件(goodFiles 和 eventFIles)的数量,如下所示:
SELECT COUNT(c.MessageTypeId) AS filesNum
FROM c
WHERE c.MessageTypeId = 4
SELECT COUNT(c.MessageTypeId) AS incidentNum
FROM c
WHERE c.MessageTypeId = 1
我需要一个 SQL 来完成所有这些操作并将其输出到 csv 文件中。任何帮助将不胜感激
非常感谢!
我尝试过这些:
SELECT COUNT(c.MessageTypeId) AS filesNum
FROM c
WHERE c.MessageTypeId = 4
SELECT COUNT(c.MessageTypeId) AS incidentNum
FROM c
WHERE c.MessageTypeId = 1
首先我需要它们成为一个查询。其次,无论如何我都会得到 1 的值。
try the code
SELECT
SUM(CASE WHEN c.MessageTypeId = 4 THEN 1 ELSE 0 END) AS filesNum,
SUM(CASE WHEN c.MessageTypeId = 1 THEN 1 ELSE 0 END) AS incidentNum
FROM c