将 DB2 SQL 十进制转换为时间 [英] Convert DB2 SQL Decimal to time
问题描述
将 DB2 SQL 十进制转换为时间我需要将十进制转换为时间.我有一个十进制时间字段,其中包含这样的数据:
Convert DB2 SQL Decimal to time I need to convert Decimal to time. I have a decimal time field that contains data like this :
123490 --12:34:90
4506 --00:45:06
171205 --17:12:05
123490 --12:34:90
4506 --00:45:06
171205 --17:12:05
等
我想转换成时间格式,然后计算两个时间列之间的最小值
I would like to convert into time format then i calculate min between two times columns
是否可以在 select 语句中使用 SQL 命令或 DB2 逻辑来执行此操作?
Is there anyway to do this with SQL commands or DB2 logic in a select statement?
推荐答案
要将其转换为有效的时间格式,您必须进行一些字符串操作,例如
To convert it to a valid time format you have to do some string manipulations like
cast( substr( right( '00' || '123456', 6) ,1,2) || ':' || substr( right( '00' || '123456', 6) ,3,2) || ':' || substr( right( '00' || '123456', 6) ,5,2) as time)
其中 123456 是您的小数点.这也适用于您的 4506 示例.如果您想避免每次都添加00",您当然也可以使用 case 语句.
where 123456 is your decimal. This would work for your 4506 example as well. You could of cause also use a case statement if you want to avaoid adding the "00" each time.
为了计算以分钟为单位的差异,可能还有其他计算选项.您可以查看 minutes_between 函数
For calculating the difference in minues there might be other calc options. You can check out the minutes_between function provided by Db2 11.1
这篇关于将 DB2 SQL 十进制转换为时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!