0
私は自分の状態が遅いが、私の場合は私の結果があまりにも多くの結果を示すときに使用した後に表示するために使用しようとします。ケースin sqlserver
select
grp.checktime,
--min(CONVERT(smalldatetime,l.checktime)) as clockin,
--max(CONVERT(smalldatetime,l.checktime)) as clockout,
ClockIn = case when min(cast(l.checktime as time)) <= cast(sc.StartTime as time)
then convert(varchar(100), cast(l.checktime as time), 100)
else 'Late ClockIn ' + convert(varchar(100), cast(l.checktime as time), 100)
end,
Clockout = case when max(cast(l.checktime as time)) >= cast(sc.EndTime as time)
then convert(varchar(100), cast(l.checktime as time), 100)
else 'Early ClockOut ' + convert(varchar(100), cast(l.checktime as time), 100)
end,
l.userid,
u.showname,
u.BADGENUMBER
from checkinout l
inner join userinfo u on l.userid = u.userid
inner join UserUsedsclasses uuc on u.userid = uuc.userid
inner join SchClass sc on uuc.SchId = sc.schClassid
inner join (
select distinct CONVERT(Date,checktime) as checktime
from checkinout
group by CONVERT(Date,checktime)
) as grp on grp.checktime = CONVERT(Date, l.checktime)
where uuc.SchId = 1 and u.badgenumber = 107
and u.badgenumber not in (79, 103, 78)
and l.checktime >= dateadd(month, datediff(month, 0, GETDATE()) , 0)
and l.checktime < dateadd(month, datediff(month, 0, GETDATE())+1, 0)
group by grp.checktime,l.userid,u.showname,u.BADGENUMBER,sc.StartTime,l.checktime,sc.EndTime
「checkinout」はどのように見えますか?私はこれがLEAD()かLAG()の良いユースケースかどうか疑問に思っています。 –
checkinoutはテーブル名です –
明らかにテーブル名です。私はサンプルデータのようにテーブルがどのように見えるのだろうかと思っています。クエリと部分出力だけを知ることは本当に有益ではありません。 –