我有一个非常复杂的数据库,我正在尝试执行一个查询,该查询返回结果计数列的所有值的总和。我可以成功确定计数值,但如何确定总和?
我的代码是:
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
答案 0 :(得分:0)
你试过了吗?
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;