SELECT Failed. 3706: (-3706) Синтаксическая ошибка: ожидалось что-то между ')' и словом 'WellResults'.
Я сгорел в TeraData, кто-нибудь знает, как это исправить? Любая помощь приветствуется.
(SELECT
Department
, SURFACE_LAT
, SURFACE_LONG
, API12
, CHEVNO
, FIELD_CODE
, OS
, AWT
, CLASS_CODE
, STATUS
, PRODUCING_METHOD
, SA_COST_CENTER_CODE
, PROPSHORT
, OCOMPLETIONDESC
, CASE
WHEN Cast(regexp_replace(trim(Left(OCompletionDesc,2)), '[^0-9]','') AS INT) < 10 and Cast(regexp_replace(trim(Left(OCompletionDesc,2)), '[^0-9]','') AS INT) > 0 and Cast(regexp_replace(trim(Left(PROPSHORT,1)), '[^0-9]','') AS INT) <> 0 THEN '0'||OReplace(OReplace(OReplace(OReplace(OReplace(OCompletionDesc,' ','WL000'),' ','WL00'),' ','WL0'),'- ','-0'),' ','WL')
ELSE OReplace(OReplace(OReplace(OReplace(OReplace(OCompletionDesc,' ','WL000'),' ','WL00'),' ','WL0'),'- ','-0'),' ','WL')
END WellNameDesc
,CASE
WHEN Cast(regexp_replace(trim(Left(PROPSHORT,2)), '[^0-9]','') AS INT) < 10 and Cast(regexp_replace(trim(Left(PROPSHORT,2)), '[^0-9]','') AS INT) > 0 and Cast(regexp_replace(trim(Left(PROPSHORT,1)), '[^0-9]','') AS INT) <> 0 THEN '0'||PROPSHORT
ELSE PROPSHORT
END LeaseID
, CASE
WHEN STATUS IN ('HA','HF','TA','ZC','ZR') THEN 'D'
WHEN STATUS in ('AC*','SM') THEN 'I'
WHEN CLASS_CODE in ('SI','OB') AND STATUS = 'SI' THEN 'I'
ELSE 'IDLE'
END EAMSTATUS
from
(SELECT
WH.AssetBK "Department"
,WB.API12BK "API12"
,WB.WellboreChevno "Chevno"
,WO.SurfaceLongitude "SURFACE_LONG"
,WO.SurfaceLatitude "SURFACE_LAT"
,WH.AssetBK "Field_Code"
,WBC.ChevronWellBoreCompletionStatusType "Status"
,WBC.AutomatedWellTester "AWT"
,WBC.CostCenterBK "SAP_COST_CENTER_CODE"
,WBC.WellClass "Class_Code"
,WBC.FinancialProducingMethodCode "Producing_Method"
,WBC.PropertyDesc "PROPSHORT"
,PT.OperationsSupervisorBK "OS"
,CASE
When ChevnoCount >1 Then left(completiondesc,length(completiondesc)-1)
Else CompletionDesc
End OCompletionDesc
FROM IDW_MASTERDATA.DIMWellbore WB
Inner JOIN (
SELECT DIMWellbore.WellboreChevno,
count(WellboreChevno) ChevnoCount
from IDW_MASTERDATA.DIMwellbore
where WellboreDescription <> 'Z*'
group by WellboreChevno) WellNames on WellNames.Chevno = DimWellbore.Chevno) WellResults
JOIN IDW_MASTERDATA.DIMWellHierarchy WH ON WH.API12BK = WB.API12BK
JOIN IDW_MASTERDATA.DIMWellOrigin WO ON WO.Chevno = WB.WellboreChevno
JOIN IDW_MASTERDATA.DIMSection SEC ON SEC.SectionBK = WO.SectionBK
JOIN IDW_MASTERDATA.DIMWellboreCompletion WBC ON WBC.API12BK = WB.API12BK
JOIN IDW_PL_PRODUCTION_UAT.DIMProductionTechnologist PT ON WBC.AssetProductionTechnologist = PT.ProductionTechnologistBK) WellResults
where Surface_LAT >0 and Class_code <> 'UNKNOWN' and Status Not In ('ZR','ZC','PA','TA','HF','HA') and Department <> 'UNKNOWN' and Chevno <> 'UNKNOWN'
Group By DEPARTMENT, SURFACE_LAT, SURFACE_LONG, API12, Chevno, FIELD_CODE, OS, AWT, CLASS_CODE, STATUS, PRODUCING_METHOD, SAP_COST_CENTER_CODE, PROPSHORT, OCOMPLETIONDESC) q3
WHERE DEPARTMENT IN ('CO','CY','KR','LH','MS','SA')
GROUP BY Department, SURFACE_LAT, SURFACE_LONG, API12, CHEVNO, FIELD_CODE, OS, AWT, CLASS_CODE, PRODUCING_METHOD, SAP_COST_CENTER_CODE, PROPSHORT, OCOMPLETIONDESC, WellNameDesc, LeaseID
ORDER BY DEPARTMENT, OCOMPLETIONDESC