gpt4 book ai didi

mysql - 如何计算 mysql 中计数列中值的总和?

转载 作者:行者123 更新时间:2023-11-30 21:57:54 24 4
gpt4 key购买 nike

我有一个非常复杂的数据库,我正在尝试执行一个查询,该查询返回结果计数列的所有值的总和。我可以成功确定计数值,但如何确定总和?

我的代码是:

SELECT COUNT(cause) as num_of_deaths
FROM deaths
WHERE rlist IN ('09A', '09B', '09N', '09C')
AND ryear IN (SELECT DISTINCT ryear FROM deaths)
AND cause IN (SELECT cause FROM icd9 WHERE description LIKE '%MN OF%')
GROUP BY cause;

每次我尝试将我的计数包含在 SUM 中时,我都会收到一条错误消息,提示“组函数的使用无效”。我该如何解决这个问题?

我的结果集如下所示:resultant set

最佳答案

你试过吗:

SELECT SUM(num_of_deaths) FROM (
SELECT COUNT(cause) as num_of_deaths
FROM deaths
WHERE rlist IN ('09A', '09B', '09N', '09C')
AND ryear IN (SELECT DISTINCT ryear FROM deaths)
AND cause IN (SELECT cause FROM icd9 WHERE description LIKE '%MN OF%')
GROUP BY cause) as nums_of_deaths;

关于mysql - 如何计算 mysql 中计数列中值的总和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44424074/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com