MySQL date_format( date, '%Y-%m-%d %h') 作为 Presto 中的“day-hour”
MySQL date_format( date, '%Y-%m-%d %h') as `day-hour` equivalent in Presto
我有列日期列,时间戳数据类型。
date
'2020-08-05 01:01:24.000'
'2020-08-05 02:02:24.000'
'2020-08-05 02:03:24.000'
我想按天分组。
所以在 MySQL 我会通过
select date_format( date, '%Y-%m-%d %h') as `day-hour`
from table
group by date_format( date, '%Y-%m-%d %h');
这将输出:
day-hour
2020-08-05 01
2020-08-05 02
如何在 Presto 中执行此操作?
您可以将这些字符串转换为 TIMESTAMP
并使用 date_trunc
将时间戳截断为小时:
WITH data(x) AS (VALUES
'2020-08-05 01:01:24.000',
'2020-08-05 02:02:24.000',
'2020-08-05 02:03:24.000')
SELECT date_trunc('hour', CAST(x AS TIMESTAMP))
FROM data
GROUP BY 1
_col0
-------------------------
2020-08-05 01:00:00.000
2020-08-05 02:00:00.000
(2 rows)
我有列日期列,时间戳数据类型。
date
'2020-08-05 01:01:24.000'
'2020-08-05 02:02:24.000'
'2020-08-05 02:03:24.000'
我想按天分组。
所以在 MySQL 我会通过
select date_format( date, '%Y-%m-%d %h') as `day-hour`
from table
group by date_format( date, '%Y-%m-%d %h');
这将输出:
day-hour
2020-08-05 01
2020-08-05 02
如何在 Presto 中执行此操作?
您可以将这些字符串转换为 TIMESTAMP
并使用 date_trunc
将时间戳截断为小时:
WITH data(x) AS (VALUES
'2020-08-05 01:01:24.000',
'2020-08-05 02:02:24.000',
'2020-08-05 02:03:24.000')
SELECT date_trunc('hour', CAST(x AS TIMESTAMP))
FROM data
GROUP BY 1
_col0
-------------------------
2020-08-05 01:00:00.000
2020-08-05 02:00:00.000
(2 rows)