我有一个表,其中包含持续时间作为包含分钟总和的列,我想将所有持续时间转换为HH:MM格式。
ECode Duration
101 186
102 1446
103 1116
输出应该是这样的:
ECode Duration
101 3.06
102 24.06
103 18.36
我想用Update语句来完成它,并希望像这样更新所有行。
寻找可以解决我的问题的查询。提前谢谢。
答案 0 :(得分:2)
一种方法如下:
SELECT ECode
CAST(Duration/ 60 AS VARCHAR(10)) + '.'
+ RIGHT('0' + CAST(Duration % 60 AS VARCHAR(2)), 2) AS Duration
FROM YourTable
答案 1 :(得分:1)
也许是这样的:
WITH CTE
AS
(
SELECT
ECode,
CAST(Duration AS INT) AS Duration
FROM
YourTable
)
SELECT
SELECT CAST(Duration/ 60 AS VARCHAR(10)) + '.'
+ RIGHT('0' + CAST(Duration % 60 AS VARCHAR(2)), 2) AS Duration
FROM
CTE