有没有办法按 SQL 中日期时间列的一部分进行分组?
Is there a way to group by part of a datetime column in SQL?
我有一个类似这样的数据框。
Time DollarVal
2020-06-25 17:48:13.636 1000
2020-06-27 17:48:13.895 1000
2020-06-27 17:48:14.101 1000
2020-06-24 17:48:14.434 1000
2020-06-22 17:48:14.709 1000
有没有办法 return table 根据时间计算美元价值的总和,精确到分钟。
例如:
Time DollarVal
17:48:13 2000
17:48:14 3000
请注意,原始数据集中的“时间”数据跨越了几天,但我只关心一天中的时间。
谢谢
我不确定是否有办法只提取时间,但您可以将其格式化为字符串:
select format_datetim(time, '%H:%i:%s') as time_only, sum(dollarval)
from t
group by time_only
order by time_only;
或者,您可以将该值转换为时间(以 Piotr 的评论为准):
select cast(time as time) as time_only, . . .
我有一个类似这样的数据框。
Time DollarVal
2020-06-25 17:48:13.636 1000
2020-06-27 17:48:13.895 1000
2020-06-27 17:48:14.101 1000
2020-06-24 17:48:14.434 1000
2020-06-22 17:48:14.709 1000
有没有办法 return table 根据时间计算美元价值的总和,精确到分钟。 例如:
Time DollarVal
17:48:13 2000
17:48:14 3000
请注意,原始数据集中的“时间”数据跨越了几天,但我只关心一天中的时间。
谢谢
我不确定是否有办法只提取时间,但您可以将其格式化为字符串:
select format_datetim(time, '%H:%i:%s') as time_only, sum(dollarval)
from t
group by time_only
order by time_only;
或者,您可以将该值转换为时间(以 Piotr 的评论为准):
select cast(time as time) as time_only, . . .