在 Oracle SQL 中根据营业时间计算时间
在 Oracle SQL 中,计算两个时间段之间的时间可以很简单。但如果需要考虑营业时间的话,计算就变得比较复杂。
营业时间规范
提供的营业时间为周一至周六 8:00 起上午至下午 6:00。要将这些小时数合并到计算中,您可以结合使用日期操作和条件逻辑。
SQL 查询
以下 SQL 查询提供了计算小时数的解决方案根据指定业务小时:
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;
解释
- 周: 查询首先使用 TRUNC( end_time, 'IW' ) 和 TRUNC( start_time, 'IW' )。这些计算给出了包含任务开始和结束的 ISO 周的开始和结束日期。
- 天数: LEAST() 和 GREATEST() 函数用于考虑部分范围开始和结束的天数,营业时间可能不适用。
- 时间: 时间差异最后一天和范围开始前一天的计算方式类似。
- 乘法:最终计算将结果乘以 24,将分钟转换为小时。
示例数据和输出
使用提供的示例data:
TASK | START_TIME | END_TIME A | 16-JAN-17 10:00 | 23-JAN-17 11:35 B | 18-JAN-17 17:53 | 19-JAN-17 08:00 C | 13-JAN-17 13:00 | 17-JAN-17 14:52 D | 21-JAN-17 10:00 | 30-JAN-17 08:52
查询输出以下结果:
TASK | START_TIME | END_TIME | WORK_DAY_HOURS_DIFF |
---|---|---|---|
A | 2017-01-16 10:00:00 (MON) | 2017-01-23 11:35:00 (MON) | 61.583333333333333 |
B | 2017-01-18 17:53:00 (WED) | 2017-01-19 08:00:00 (THU) | .116666666666667 |
C | 2017-01-13 13:00:00 (FRI) | 2017-01-17 14:52:00 (TUE) | 31.866666666666667 |
D | 2017-01-21 10:00:00 (SAT) | 2017-01-30 08:52:00 (MON) | 68.866666666666667 |
这些结果准确反映了基于指定营业时间的工作时间数。
以上是如何在 Oracle SQL 中计算两个日期之间的营业时间?的详细内容。更多信息请关注PHP中文网其他相关文章!

mysqlblobshavelimits:tinyblob(255bytes),blob(65,535 bytes),中间布洛布(16,777,215个比例),andlongblob(4,294,967,967,295 bytes).tousebl观察性:1)考虑performance impactsandSandStorelargeblobsextern; 2)管理backbackupsandreplication carecration; 3)usepathsinst

自动化在MySQL中创建用户的最佳工具和技术包括:1.MySQLWorkbench,适用于小型到中型环境,易于使用但资源消耗大;2.Ansible,适用于多服务器环境,简单但学习曲线陡峭;3.自定义Python脚本,灵活但需确保脚本安全性;4.Puppet和Chef,适用于大规模环境,复杂但可扩展。选择时需考虑规模、学习曲线和集成需求。

是的,YouCansearchInIdeAblobInMysqlusingsPecificteChniques.1)转换theblobtoautf-8StringWithConvertFunctionWithConvertFunctionandSearchusiseLike.2)forCompresseBlyblobs,useuncompresseblobs,useuncompressbeforeconversion.3)acpperformance impperformance imperformance imptactsanddataEccoding.4)

mysqloffersvariousStringDatatYpes:1)charforfixed Lengtth Strings,IdealforConsistLengthDatalikeCountryCodes; 2)varcharforvariable长度长,合适的forfieldslikenames; 3)texttypefesforepesforlargertext,forforlargertext,goodforforblogblogpostsbutcan impactcuctcuctcuctpercrance; 4)biland;

TomasterMySQLBLOBs,followthesesteps:1)ChoosetheappropriateBLOBtype(TINYBLOB,BLOB,MEDIUMBLOB,LONGBLOB)basedondatasize.2)InsertdatausingLOAD_FILEforefficiency.3)Storefilereferencesinsteadoffilestoimproveperformance.4)UseDUMPFILEtoretrieveandsaveBLOBsco

blobdatatypesinmysqlareusedforvorvoringlargebinarydatalikeimagesoraudio.1)useblobtypes(tinyblobtolonglongblob)基于dondatasizeneeds。 2)库孔素pet petooptimize绩效。3)考虑Xternal Storage Forel Blob romana databasesizerIndimprovebackupe

toadDuserStomySqlfromtheCommandline,loginasroot,thenusecreateuser'username'@'host'host'Indessifiedby'password'; tocreateanewuser.grantpermissionswithgrantprantallprivilegesondatabase

mySqlofferSeightStringDatateTypes:char,varchar,二进制,二进制,varbinary,blob,文本,枚举,枚举和set.1)长度,理想的forconsistentDatatalIkeCountryCodes.2)varcharisvariable长度,长度,效率foriforitifforiticforiticforiticforiticforiticforitic forvaryingdatalikename.3)


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Dreamweaver CS6
视觉化网页开发工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

记事本++7.3.1
好用且免费的代码编辑器

禅工作室 13.0.1
功能强大的PHP集成开发环境