비즈니스 시간 사양
는 월요일부터 토요일까지 8:00입니다. 오전 6 시부 터 오후 6시. 이 시간을 계산에 통합하려면 날짜 조작과 조건부 로직의 조합을 사용할 수 있습니다.
SQL 쿼리
다음 SQL 쿼리는 시간 계산을위한 솔루션을 제공합니다. 지정된 비즈니스 시간을 기준으로 : 작업 선택, start_time, end_time, 둥근( ( - ISO 주가 시작된 전체 몇 주 차이를 계산하십시오. (trunc (end_time, 'iw') - trunc (start_time, 'iw')) * (10/24) * (6/7) - 마지막 주에 하루 종일 추가하십시오. 최소 (trunc (end_time) -trunc (end_time, 'iw'), 6) * (10/24) - 시작 날짜 전 요일부터 하루 종일 며칠을 빼십시오. - 최소 (trunc (start_time) -trunc (start_time, 'iw'), 6) * (10/24) - 마지막 날의 시간을 추가하십시오 최소 (가장 큰 (End_Time -Trunc (end_time) -8/24, 0), 10/24) - 범위가 시작되기 전날 시간을 빼십시오. - 최소 (Greatest (start_time -trunc (start_time) -8/24, 0), 10/24) )) - 하루 종일 부분이 아닌 몇 분을 곱하십시오. * 24, 15- 소수점 이하 수 ) work_day_hours_diff로 your_table;
설명
SELECT task, start_time, end_time, ROUND( ( -- Calculate the full weeks difference from the start of ISO weeks. ( TRUNC( end_time, 'IW' ) - TRUNC( start_time, 'IW' ) ) * (10/24) * (6/7) -- Add the full days for the final week. LEAST( TRUNC( end_time ) - TRUNC( end_time, 'IW' ), 6 ) * (10/24) -- Subtract the full days from the days of the week before the start date. - LEAST( TRUNC( start_time ) - TRUNC( start_time, 'IW' ), 6 ) * (10/24) -- Add the hours of the final day LEAST( GREATEST( end_time - TRUNC( end_time ) - 8/24, 0 ), 10/24 ) -- Subtract the hours of the day before the range starts. - LEAST( GREATEST( start_time - TRUNC( start_time ) - 8/24, 0 ), 10/24 ) ) -- Multiply to give minutes rather than fractions of full days. * 24, 15 -- Number of decimal places ) AS work_day_hours_diff FROM your_table;
2017-01-16 10:00:00 (mon)
&&] 2017-1-23 11:35:00 (월) 00 (wed)SELECT task, start_time, end_time, ROUND( ( -- Calculate the full weeks difference from the start of ISO weeks. ( TRUNC( end_time, 'IW' ) - TRUNC( start_time, 'IW' ) ) * (10/24) * (6/7) -- Add the full days for the final week. LEAST( TRUNC( end_time ) - TRUNC( end_time, 'IW' ), 6 ) * (10/24) -- Subtract the full days from the days of the week before the start date. - LEAST( TRUNC( start_time ) - TRUNC( start_time, 'IW' ), 6 ) * (10/24) -- Add the hours of the final day LEAST( GREATEST( end_time - TRUNC( end_time ) - 8/24, 0 ), 10/24 ) -- Subtract the hours of the day before the range starts. - LEAST( GREATEST( start_time - TRUNC( start_time ) - 8/24, 0 ), 10/24 ) ) -- Multiply to give minutes rather than fractions of full days. * 24, 15 -- Number of decimal places ) AS work_day_hours_diff FROM your_table;
2017-01-19 08:00:00 (thu)
2017-01-21 10:00:00 (sat) | 2017-01-30 08:52:00 (mon) | 68.8666666666666667 | |
---|---|---|---|
부인 성명: 제공된 모든 리소스는 부분적으로 인터넷에서 가져온 것입니다. 귀하의 저작권이나 기타 권리 및 이익이 침해된 경우 자세한 이유를 설명하고 저작권 또는 권리 및 이익에 대한 증거를 제공한 후 이메일([email protected])로 보내주십시오. 최대한 빨리 처리해 드리겠습니다.
Copyright© 2022 湘ICP备2022001581号-3