找到多个sql计数的总和

时间:2014-07-03 11:13:20

标签: sql aggregate-functions jdeveloper

我正在尝试查找下面查询中所述的2个计数值的总和。即使查询工作正常我只是找到计数值,当我试图找到计数值的总和时,我得到一个错误...请帮助..

SELECT COUNT(BUG_ID) BUG_COUNT,
COUNT(STATUS) CLOSED_COUNT,
(BUG_COUNT + CLOSED_COUNT) AS  TOTAL_COUNT
FROM bugzilla_dashboard WHERE CATEGORY='Legacy';

我收到错误消息..

ORA-00904: "CLOSED_COUNT": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error at Line: 3 Column: 14

3 个答案:

答案 0 :(得分:4)

试试这个

SELECT COUNT(BUG_ID) BUG_COUNT,COUNT(STATUS) CLOSED_COUNT,
      (COUNT(BUG_ID) + COUNT(STATUS)) AS  TOTAL_COUNT
FROM bugzilla_dashboard 
WHERE CATEGORY='Legacy';

或者:

SELECT BUG_COUNT,CLOSED_COUNT,(BUG_COUNT + CLOSED_COUNT) AS  TOTAL_COUNT
FROM
(
  SELECT COUNT(BUG_ID) BUG_COUNT,
         COUNT(STATUS) CLOSED_COUNT
  FROM bugzilla_dashboard 
  WHERE CATEGORY='Legacy'
) Tmp

答案 1 :(得分:1)

SELECT COUNT(BUG_ID) BUG_COUNT,
COUNT(STATUS) CLOSED_COUNT,
(COUNT(BUG_ID) + COUNT(STATUS)) AS  TOTAL_COUNT
FROM bugzilla_dashboard WHERE CATEGORY='Legacy';

...明显

答案 2 :(得分:0)

请尝试此查询

   SELECT 
    (COUNT(BUG_ID) +COUNT(STATUS)) 
    AS  
    TOTAL_COUNT 
    FROM 
    bugzilla_dashboard 
    WHERE 
    CATEGORY='Legacy';