【发布时间】:2026-02-16 13:20:05
【问题描述】:
我想从每小时的价值中得出总和。 看截图:
为此,我使用了“datepart”。 现在,我想要时间戳格式的日期部分中的这些值。 此外,我想填满一天中的其他时间,所以我想每天有 24 行。
你能帮帮我吗?
【问题讨论】:
标签: sql sum timestamp summary datepart
我想从每小时的价值中得出总和。 看截图:
为此,我使用了“datepart”。 现在,我想要时间戳格式的日期部分中的这些值。 此外,我想填满一天中的其他时间,所以我想每天有 24 行。
你能帮帮我吗?
【问题讨论】:
标签: sql sum timestamp summary datepart
首先,创建一个Numbers Table
然后这样做:
select N1.Number,
sum(case when P2.Typ = 'outbound' then 1 else 0 end) as Outbound,
sum(case when P2.Typ = 'inbound' then 1 else 0 end) as Inbound
from Numbers N1
left join #pstntable P2
on N1.Number = DatePart(hh, P2.Date)
and P2.Date between @_StartTime and @_EndTime
where N1.Number <= 24
group by N1.Number
【讨论】: