【发布时间】:2019-12-18 04:49:44
【问题描述】:
这是我原来的查询语句....
SELECT airline company, country, count(country) "The no.of times the airline visits the country"
FROM [table]
GROUP BY airline company, country
我认为这很好用……直到我想在有错误的地方添加一个 case 语句……
修改后,
Airline Company : country : No.Of times
Singapore Airline : SG : 5
Singapore Airline : MAL : 7
Japan Airline : SG : 3
Japan Airline : MAL : 2
在第一个查询语句之后,结果如上所示。无论国家“MAL”的航空公司如何,我都想将 No.of times 列的值更改为 0。所以我尝试将 case 语句添加到 select 中,但它给了我类似 group function is not allowed
SELECT airline company, country, CASE WHEN country = 'MAL' THEN 0
ELSE count(country) "The no.of times the airline visits the country" END
FROM [table]
GROUP BY airline company, country, CASE WHEN country = 'MAL' THEN 0
ELSE count(country) "The no.of times the airline visits the country" END
我该如何解决?
【问题讨论】:
-
您当前的查询应该已经生成了您想要的输出。它有什么问题?