我在没有CASE功能的情况下运行了以下查询,并从同一个表中选择了两个以下的字段。该版本运行完美且没有错误。以下版本告诉我,我错过了正确的括号。我已经仔细研究了这段代码,并且在我的生活中不能找到问题所在。这段代码和代码之间没有任何区别,除了在这一段我添加了CASE函数的行,我选择了另外两个字段,“ID_OPER_RESPONSIBLE”,“DT_ASSIGNED”和“TS_OPER_LAST_UPDTD”。请帮忙。非常感谢。
select * From
(select
"Feeder #",
"WR #",
"Building",
"Area",
"SVC Ctr",
"CREW HQ",
"Job Type",
"Wk Tp",
"Description",
"Project Code",
"Status",
"Status Desc",
"Start Date",
"Req'd Date",
"Est Dlrs $",
"Est FPL Pay $",
"Est Ctr $",
"Est Matl $",
"Est Hrs",
"As Blt CMH",
"Act Dlrs $",
"Act FPL Pay $",
"Act Ctr $",
"Act Matl $",
"Act Hrs",
"CD_RQMT",
"Req-Stat-Date",
"Ad Street Prefix",
"ID_OPER_RESPONSIBLE",
"DT_ASSIGNED",
"TS_OPER_LAST_UPDTD",
"JOB CODE"
from
(select * from (select distinct
ptw."TXT_REFERENCE_3" "Feeder #",
To_Char(ptw."CD_WR") "WR #",
padd."NM_BUILDING" "Building",
ptw."CD_DIST" "Area",
ptw."CD_AREA" "SVC Ctr",
ptw."CD_CREWHQ" "CREW HQ",
ptw."TP_JOB" "Job Type",
ptw."TP_WR" "Wk Tp",
ptw."DS_WR" "Description",
ptw."CD_PROJECT" "Project Code",
ptw."CD_STATUS" "Status",
pstat."DS_STATUS" "Status Desc",
ptw."DT_SCHED" "Start Date",
ptw."DT_REQUIRED" "Req'd Date",
SUM(ptse."AMT_ADMIN_OH"+ptse."AMT_LBR_CMPNY"+ptse."AMT_MATL_OH"+ptse."AMT_MATL" + ptse."AMT_LBR_CNTCR") "Est Dlrs $",
ptse."AMT_LBR_CMPNY" "Est FPL Pay $",
ptse."AMT_LBR_CNTCR" "Est Ctr $",
ptse."AMT_MATL" "Est Matl $",
sum(ptse."HR_LBR_CMPNY"+ ptse."HR_LBR_CNTCR") "Est Hrs",
ptsasb."HR_LBR_CMPNY" "As Blt CMH",
SUM(ptsact."AMT_ADMIN_OH" + ptsact."AMT_EQUIP_OH"+ptsact."AMT_LBR_CMPNY"+ ptsact."AMT_LBR_CNTCR" + ptsact."AMT_MATL_OH"+ptsact."AMT_MATL") "Act Dlrs $",
ptsact."AMT_LBR_CMPNY" "Act FPL Pay $",
ptsact."AMT_LBR_CNTCR" "Act Ctr $",
ptsact."AMT_MATL" "Act Matl $",
ptsact."HR_LBR_CMPNY" "Act Hrs",
pts."CD_RQMT",
pts."CD_RQMT"||'-'||pts."ST_RQMT"||'-'||pts."TS_OPER_LAST_UPDTD" As "Req-Stat-Date",
padd."AD_STREET_PFX" "Ad Street Prefix",
pts."ID_OPER_RESPONSIBLE" "ID_OPER_RESPONSIBLE",
pts."DT_ASSIGNED" "DT_ASSIGNED",
Case When pts."ST_RQMT" = 'C' Then pts."TS_OPER_LAST_UPDTD" End "TS_OPER_LAST_UPDTD",
RANK() OVER (PARTITION BY ptex."CD_WR" ORDER BY ptex."CD_SEQ" DESC) "RNK",
ptex."CD_JOB" "JOB CODE"
from
"PSWMS"."TWMWR" ptw
LEFT JOIN "PSWMS"."TWMMILESTONERQMT" pts ON ptw."CD_WR" = pts."CD_WR"
LEFT JOIN "PSWMS"."TWMWRSUMMARY_EST" ptse ON ptw."CD_WR" = ptse."CD_WR"
LEFT JOIN "PSWMS"."TWMWRSUMMARY_ASB" ptsasb ON ptw."CD_WR" = ptsasb."CD_WR"
LEFT JOIN "PSWMS"."TWMWRSUMMARY_ACT_EXT" ptsact ON ptw."CD_WR" = ptsact."CD_WR"
LEFT JOIN "PSWMS"."TWMSTATUS" pstat ON ptw."CD_STATUS" = pstat."CD_STATUS" AND ptw."TP_WR" = pstat."TP_WR"
LEFT JOIN "PSWMS"."TWMADDRESS" padd ON ptw."CD_ADDRESS_JOB" = padd."CD_ADDRESS"
LEFT JOIN "PSWMS"."TWMIFEXTWRDETAILS" ptex ON ptw."CD_WR" = ptex."CD_WR"
WHERE
pts."CD_RQMT" in ('211','215','399','498','699','818') AND
((ptw."CD_STATUS" NOT LIKE '%X%') OR (ptw."CD_STATUS" in ('10','20','30','40','50','60','70','80','90'))) AND
((ptw."DT_SCHED" >= TO_DATE('2012-10-01 00:00:00', 'YYYY-MM-DD HH24:Mi:SS')) OR (ptw."DT_SCHED" IS NULL)) AND
ptw."TP_JOB" IN ('62A','62B','62C','62H','62J','62L','85A','85A_IRHH','85A_LAT','85A_MPI','85A_POIRHH','85A_POIVIS','ADDLCONT_FT','STORMFLWUP','73E','84A','84K_EEI','84N','84B','84C','84C_ADDPF','84C_INSP','84D','84D_FDR','85D','85D_ETS','85E','85K','85S','86A','86A_POW','86C','86D','86D_RAS')
group by
ptw."CD_DIST",
ptw."CD_AREA",
ptw."CD_CREWHQ",
ptw."TP_JOB",
ptw."TP_WR",
ptw."CD_WR",
ptw."DS_WR",
ptw."CD_PROJECT",
ptw."TXT_REFERENCE_3",
ptw."CD_STATUS",
pstat."DS_STATUS",
ptw."DT_SCHED",
ptw."DT_REQUIRED",
ptse."AMT_LBR_CNTCR",
ptse."HR_LBR_CMPNY",
ptsasb."HR_LBR_CMPNY",
ptsact."AMT_LBR_CNTCR",
ptsact."HR_LBR_CMPNY",
pts."CD_RQMT",
pts."ST_RQMT",
pts."TS_OPER_LAST_UPDTD",
padd."AD_STREET_PFX",
ptse."AMT_LBR_CMPNY",
ptse."AMT_MATL",
ptsact."AMT_LBR_CMPNY",
ptsact."AMT_MATL",
padd."NM_BUILDING",
pts."ID_OPER_RESPONSIBLE",
pts."DT_ASSIGNED",
pts."TS_OPER_LAST_UPDTD"
ptex."CD_WR",
ptex."CD_SEQ",
ptex."CD_JOB") where RNK = 1))
PIVOT (max("Req-Stat-Date") "Req", max("ID_OPER_RESPONSIBLE") "Req Assigned to", max("DT_ASSIGNED") "Req Assigned Date", max("TS_OPER_LAST_UPDTD") "Req Comp Date" for "CD_RQMT" in ('211' "211",'215' "215",'399' "399",'498' "499",'699' "699",'818' "818"))
答案 0 :(得分:0)
这与案例表达无关。您在pts."TS_OPER_LAST_UPDTD"
之后缺少逗号:
pts."DT_ASSIGNED",
pts."TS_OPER_LAST_UPDTD"
------------------------^
ptex."CD_WR",
ptex."CD_SEQ",
ptex."CD_JOB") where RNK = 1))
PIVOT (max("Req-Stat-Date") "Req", max("ID_OPER_RESPONSIBLE") "Req Assigned to", max("DT_ASSIGNED") "Req Assigned Date", max("TS_OPER_LAST_UPDTD") "Req Comp Date" for "CD_RQMT" in ('211' "211",'215' "215",'399' "399",'498' "499",'699' "699",'818' "818"))
如果您使用像SQL Developer这样的IDE,那么在您尝试运行查询之前应该突出显示类似的东西;即使您没有大多数客户端(包括SQL * Plus),也应该报告错误所在的行号。在这种情况下,它实际上指向下一行的第一个字符,但这仍然让你足够接近能够发现它。