sql >> データベース >  >> RDS >> Sqlserver

日が異なる場合のSQL Serverの追跡スケジュールされたシフト

    以下は、シフトの表を作成します。何をしたいのか明確ではありませんが、ここに示す計算のいくつかを使用して、イベントの日付/時刻からのシフトを決定するリバース エンジニアリングができるはずです。

    編集 :caseを修正 2/2/3/2 パターンに対応します。

    <プレ>; with Samples as ( -- Start at the beginning of 2013. select Cast( '01-01-2013 00:00' as DateTime ) as Sample union all -- Add hours up to the desired end date. select DateAdd( hour, 1, Sample ) from Samples where Sample <= '2013-01-30' ), ExtendedSamples as ( -- Calculate the number of days since the beginning of the first shift on 1/1/2013. select Sample, DateDiff( hour, '01-01-2013 07:00', Sample ) / 24 as Days from Samples ), Shifts as ( -- Calculate the shifts for each day. select *, case when ( Days + 1 ) % 9 in ( 0, 1, 4, 5 ) then 'C/D' else 'A/B' end as Shifts from ExtendedSamples ) select *, case when DatePart( hour, Sample ) between 7 and 18 then Substring( Shifts, 1, 1 ) else Substring( Shifts, 3, 1 ) end as Shift from Shifts option ( maxrecursion 0 )

    1. Doctrine(symfonyプロジェクト内)はソケットを介して接続できません

    2. Docker-さまざまなWebサイトのホストとコンテナーでApacheを実行します

    3. PHPチェックMySQL最終行

    4. PHP PDO SQLは、すべての行ではなく1行のデータのみを返します