我需要按描述分组,所以我一周中的所有日子都在同一行中,例如“不合理”必须在一行中显示一次,但是当我使用 Group By 语句时,我没有得到它们连接有人可以帮我吗..谢谢
select Emp.ID,
sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork as SchedWork,
case when absence.description is null then case when absence1.description is null then 'Unjustified' else absence1.description end else absence.description end as description,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Mon' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Tue' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Wed' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Thu' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Fri' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Sat' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end,
case when dbo.ta_dayofweek(ta_timecard.schedindate) = 'Sun' then sum(case when ta_timecarddet.trstype = 6 or ta_timecarddet.trstype = 11 then ta_timecard.scheduledwork else case when ta_timecardlinks.fromtimer = ta_timecard.schedintime then ta_timecardlinks.effdurationr + ta_timecard.rndminin else case when ta_timecardlinks.totimer = ta_timecard.schedouttime then ta_timecardlinks.effdurationr - ta_timecard.rndminout else ta_timecardlinks.effdurationr end end end) / ta_timecard.scheduledwork end
from ta_timecarddet
inner join ta_timecard on ta_timecarddet.timecardid = ta_timecard.id
inner join emp on ta_timecard.empid = emp.id
inner join ta_schedulehist on ta_timecard.schedhistid = ta_schedulehist.id
left outer join ta_timecardlinks on ta_timecarddet.id = ta_timecardlinks.tctrsid
left outer join absence on ta_timecard.leavetype = absence.id
left outer join absence absence1 on ta_timecardlinks.leavetype = absence1.id
where ta_timecarddet.trstype in (1, 5, 6, 11)
and ta_timecard.worktype in (1, 4, 5, 8)
Group BY absence.description, ta_timecard.ScheduledWork, Emp.ID,absence1.description, dbo.ta_dayofweek(ta_timecard.schedindate)