在ireport设计器

时间:2015-05-26 13:06:03

标签: sql oracle jasper-reports

我在iReport设计器查询资源管理器中运行以下SQL查询:

SELECT 
A.DOC_TYPE AS DOC_TYPE,(CASE
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 01 THEN 'January'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 02 THEN 'February'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 03 THEN 'March'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 04 THEN 'April'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 05 THEN 'May'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 06 THEN 'June'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 07 THEN 'July'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 08 THEN 'Augst'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 09 THEN 'September'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 10 THEN 'October'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 11 THEN 'November'
WHEN EXTRACT(MONTH FROM  A.UPLOAD_DT) = 12 THEN 'December'
END) AS M, EXTRACT(YEAR FROM  A.UPLOAD_DT) AS Y,SUM(A.TOTAL) AS TOTAL
FROM
(select DOC_TYPE, UPLOAD_DT, count(DOC_TYPE) as TOTAL
from CASE_UPLOADS
where UPLOAD_DT >= '01-JAN-15'
AND UPLOAD_DT <= '31-MAR-15'
AND DOC_TYPE = 'QR7'
OR DOC_TYPE = 'SAR7'
group by DOC_TYPE,UPLOAD_DT
order by DOC_TYPE) A
GROUP BY DOC_TYPEY,M,TO_CHAR (A.UPLOAD_DT, 'MM')
ORDER BY DOC_TYPE,Y, TO_CHAR (A.UPLOAD_DT, 'MM')

它让我跟着错误:

ORA:00904:"M":Invalid Identifier

有人可以告诉我为什么会收到此错误?我可以通过哪种方式解决它?

我在其他类似的查询上工作,它工作正常。这是查询:

SELECT CASE WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 01 THEN 'January'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 02 THEN 'February'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 03 THEN 'March'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 04 THEN 'April'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 05 THEN 'May'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 06 THEN 'June'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 07 THEN 'July'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 08 THEN 'Augst'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 09 THEN 'September'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 10 THEN 'October'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 11 THEN 'November'
     WHEN EXTRACT(MONTH FROM app_pgm_req_dt) = 12 THEN 'December'
   END AS MONTH,
   EXTRACT(YEAR FROM app_pgm_req_dt) AS YEAR,
   COUNT(*) 
  FROM app_pgm_choice 
 GROUP BY YEAR, MONTH, TO_CHAR (app_pgm_req_dt, 'MM')
 ORDER BY YEAR, TO_CHAR (app_pgm_req_dt, 'MM');

1 个答案:

答案 0 :(得分:3)

据推测,您收到错误是因为select * from V$DBLINK;中通常不允许SELECT中定义的列别名:

group by

这取决于数据库。

相反,您可以使用此表达式:

GROUP BY DOC_TYPEY, M, TO_CHAR(A.UPLOAD_DT, 'MM')
--------------------^

因为您还需要GROUP BY DOC_TYPEY, EXTRACT(MONTH FROM A.UPLOAD_DT), EXTRACT(YEAR FROM A.UPLOAD_DT) 中的年份。

至于为什么其他版本有效,我想你可能在group by中有一个名为month的列。或者,它可能连接到 支持app_pgm_choice子句中的别名的数据库。

顺便说一句,您有没有使用group by的原因?