我有一个包含4列(TIME(0)
数据类型)的SQL Server表。
每行对应一天,所以我有:
Col Time 1 -------- Col Time 2 ------ Col Time 3
'03:23:12' -------- '21:33:04' ------ '07:44:11'
'21:14:45' -------- '12:43:44' ------ '01:56:43'
'15:22:36' -------- '19:33:55' ------ '04:03:11'
'08:21:46' -------- '01:23:14' ------ '06:09:11'
我想SUM
每列,以便我可以获得总小时,分钟和秒(hh:mm:ss
)。
因此,例如Col Time 1
我应该:
48:54:46
答案 0 :(得分:4)
首先,您的最终值应为48:22:19
而不是48:54:46
。
其次,您无法使用TIME
类型来接收所需的结果,因为hh
的元素范围是两位数,范围从0
到 23
,表示小时(More information)。
这是一种解决方法,首先您SUM
TIME
列转换秒中的每个值,然后单独找到小时,分钟和秒:
SELECT CAST(t.time_sum/3600 AS VARCHAR(2)) + ':'
+ CAST(t.time_sum%3600/60 AS VARCHAR(2)) + ':'
+ CAST(((t.time_sum%3600)%60) AS VARCHAR(2))
FROM ( SELECT SUM(DATEDIFF(S, '00:00:00', col1)) AS time_sum
FROM tbl) t
答案 1 :(得分:-2)
我找到了更简单的方法。
var skillArray = [
{ID: 1, name: "الغطس"},
{ID: 2, name: "الحريق"},
{ID: 3, name: "المعالجة"},
{ID: 4, name: "الميكانيكا"},
{ID: 5, name: "السيول"},
{ID: 6, name: "التغريز"},
{ID: 7, name: "الكهرباء"},
{ID: 8, name: "الاحتفالات"},
{ID: 9, name: "المناسبات"},
{ID: 10, name: "الصلاة"}
]
var splitstr = ["9", "7"]
const removeSkills = (source, removeList) => {
return source.reduce((prev, curr) => {
if(!removeList.includes(curr.ID.toString()) ){
return prev.concat(curr)
}
return prev
}, [])
}
const result = removeSkills(skillArray, splitstr)
console.log(result)