日期:2014-05-17  浏览次数:20783 次

将oracle查询的数据放入到表中,再次查询的时候报ora-00942
大家给我看看,哪里有错啊?
SELECT TICKETNUMBER, TICKETTYPE, VERSIONNUMBER, STAGENAME, DTANALYZED, GISPROCESSID, PROCESSSTATUS, DTRECEIVED, USERID, USERNAME, 
  FIRSTNAME, LASTNAME, NUMBEROFDAYS, (SELECT COUNT(GISPROCESSID) AS COUNTTICKETS FROM AA ) COUNTTICKETS
FROM (SELECT TICKETNUMBER, TICKETTYPE, VERSIONNUMBER, STAGENAME, DTANALYZED, GISPROCESSID, PROCESSSTATUS, DTRECEIVED, USERID, 
  USERNAME, FIRSTNAME, LASTNAME, NUMBEROFDAYS 
  FROM REPORT_PERFORMANCEOFANALYZER
  WHERE (DTANALYZED IS NULL)
  UNION ALL
  SELECT TICKETNUMBER, TICKETTYPE, VERSIONNUMBER, STAGENAME, DTANALYZED, GISPROCESSID, PROCESSSTATUS, DTRECEIVED, USERID, 
  USERNAME, FIRSTNAME, LASTNAME, NUMBEROFDAYS
  FROM REPORT_PERFORMANCEOFANALYZER REPORT_PERFORMANCEOFANALYZER_1
  ) AA
ORDER BY USERNAME

------解决方案--------------------
with aa as
 (SELECT TICKETNUMBER, TICKETTYPE, VERSIONNUMBER, STAGENAME, DTANALYZED,
GISPROCESSID, PROCESSSTATUS, DTRECEIVED, USERID, USERNAME, FIRSTNAME,
LASTNAME, NUMBEROFDAYS
FROM REPORT_PERFORMANCEOFANALYZER
WHERE (DTANALYZED IS NULL)
UNION ALL
SELECT TICKETNUMBER, TICKETTYPE, VERSIONNUMBER, STAGENAME, DTANALYZED,
GISPROCESSID, PROCESSSTATUS, DTRECEIVED, USERID, USERNAME, FIRSTNAME,
LASTNAME, NUMBEROFDAYS
FROM REPORT_PERFORMANCEOFANALYZER REPORT_PERFORMANCEOFANALYZER_1)
SELECT TICKETNUMBER, TICKETTYPE, VERSIONNUMBER, STAGENAME, DTANALYZED,
GISPROCESSID, PROCESSSTATUS, DTRECEIVED, USERID, USERNAME, FIRSTNAME,
LASTNAME, NUMBEROFDAYS,
(SELECT COUNT(GISPROCESSID) AS COUNTTICKETS FROM AA) COUNTTICKETS
FROM AA
 ORDER BY USERNAME;