【发布时间】:2021-12-28 18:15:20
【问题描述】:
我有一个包含整数值的表。我需要将整数值转换为 24 小时格式,我该怎么做我尝试使用 FOM/60 但它给出了错误的结果
来自------------我想要的 570 9:30 600 10:00 700 11:40 1020 17:00【问题讨论】:
我有一个包含整数值的表。我需要将整数值转换为 24 小时格式,我该怎么做我尝试使用 FOM/60 但它给出了错误的结果
来自------------我想要的 570 9:30 600 10:00 700 11:40 1020 17:00【问题讨论】:
使用时间类型,您只需将分钟添加到午夜
with table1 (val) as (values 570, 600, 700, 1020, 1234)
select time('00:00') + val minutes from table1
【讨论】:
使用这个片段:
CREATE TABLE numbers (
Num INTEGER
);
INSERT INTO numbers VALUES (570);
INSERT INTO numbers VALUES (600);
INSERT INTO numbers VALUES (700);
INSERT INTO numbers VALUES (1020);
SELECT cast(Num/60 as nvarchar)+':'+right ('00'+ltrim(str( Num%60 )),2 ) FROM numbers
输出:
9:30
10:00
11:40
17:00
【讨论】: