在下面的查询中,我有2行连续9周有第一行 REG_HRS 13小时和的第二行 OT_HRS 5小时
我希望第9周的所有值都在同一行
Select VP.PERSONID as EMPL,
VP.HOMELABORLEVELNM3 as DEPT,
--TO_CHAR(X.APPLYDTM, 'DD-MM-YYYY') AS LABOR_DATE,
to_char(X.APPLYDTM - 7/24,'IW') AS WEEK,
Case when P.NAME = 'US-ABS' then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as ABS_HRS,
Case when P.NAME = 'US-Regular' then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as REG_HRS,
Case when P.NAME = 'US-Overtime' then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as OT_HRS,
Case when P.NAME = 'US-Doubletime' then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as DBL_HRS,
Case when P.NAME = 'US-VAC' then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as VAC_HRS,
Case when P.NAME = 'US-HOL' then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as HOL_HRS,
SUM(X.DURATIONSECSQTY/3600.0) AS Totals,
Case when P.NAME = 'US-ABS' and SUM(X.WAGEAMT) != 0 then SUM(X.WAGEAMT) else 0 end as ABS_DLRS,
Case when P.NAME = 'US-Regular' and SUM(X.WAGEAMT) != 0 then SUM (X.WAGEAMT) else 0 end as REG_DLRS,
Case when P.NAME = 'US-Overtime' and SUM(X.WAGEAMT) != 0 then SUM(X.WAGEAMT) else 0 end as OT_DLRS,
Case when P.NAME = 'US-Doubletime' and SUM(X.WAGEAMT) != 0 then SUM(X.WAGEAMT) else 0 end as DBL_DLRS,
Case when P.NAME = 'US-VAC' and SUM(X.WAGEAMT) != 0 then SUM(X.WAGEAMT) else 0 end as VAC_DLRS,
Case when P.NAME = 'US-HOL' and SUM(X.WAGEAMT) != 0 then SUM(X.WAGEAMT) else 0 end as HOL_DLRS,
Case when P.NAME in ('USKEANE- Shift Prem','USKEANE- Shift Prem OT','USKEANE- Shift Prem DT') then SUM(X.DURATIONSECSQTY/3600.0) else 0 end as NITE_PREM
from VP_EMPLOYEEV42 VP,
WFCTOTAL X,
PAYCODE P
where
VP.PERSONID = X.EMPLOYEEID and
X.PAYCODEID = P.PAYCODEID and
--X.EMPLOYEEID = CA.PERSONID and
--CA.CUSTOMDATADEFID ='153' and
--X.TIMESHEETITEMID = TS.TIMESHEETITEMID and
P.NAME in ('US-Regular','US-Overtime','US-Doubletime','USKEANE- Shift Prem','USKEANE- Shift Prem OT','USKEANE- Shift Prem DT') AND
X.EMPLOYEEID in (select personid from PERSONCSTMDATA where CUSTOMDATADEFID ='154' and PERSONCSTMDATATXT = 'USKEANE')
and VP.PERSONID = '13702'
and X.APPLYDTM between '28-FEB-19' and '01-MAR-19'
group by VP.PERSONID, VP.HOMELABORLEVELNM3, P.NAME, to_char(X.APPLYDTM - 7/24,'IW')
ORDER BY VP.PERSONID
答案 0 :(得分:1)
Oracle使用ANSI标准||
进行字符串连接:
CASE WHEN p.NAME = 'US-Regular'
THEN '$' || CAST(x.WAGEAMT AS VARCHAR(15))
ELSE '0' END AS REG_DOLLARS
此外,CASE
表达式的所有分支都必须具有相同的类型。由于您要在THEN
分支中使用文本,因此ELSE
分支也应包含文本。