我有这些功能查询,我需要将 UTC 中的时间戳更改为不同时区的时间戳
SELECT max(user_id) AS user_id,
AVG((model_v3)*40) AS avg_score,
SUM((model_v3)*40) AS sum_score,
COUNT(*) AS total_inputs,
min(`date_cet`) AS oldest_date,
max(`date_cet`) AS newest_date,
case
when TIME(`date_cet`) between '03:00:00' and '07:59:59' then 6
when TIME(`date_cet`) between '08:00:00' and '11:59:59' then 10
when TIME(`date_cet`) between '12:00:00' and '15:59:59' then 14
when TIME(`date_cet`) between '16:00:00' and '19:59:59' then 18
when TIME(`date_cet`) between '20:00:00' and '02:59:59' then 22
end as 'time_intervals_hours'
FROM phonation_features
WHERE `date_cet` >= CURRENT_TIMESTAMP() - interval 10000 DAY AND user_id = 5
GROUP BY time_intervals_hours
ORDER BY time_intervals_hours ASC
我处理查询的唯一方法是使用CONVERT_TZ()
如下:
SELECT
max(user_id) AS user_id,
AVG((model_v3)*40) AS avg_score,
SUM((model_v3)*40) AS sum_score,
COUNT(*) AS total_inputs,
min(convert_tz(date_cet, 'UTC', 'Europe/Paris')) AS oldest_date,
max(convert_tz(date_cet, 'UTC', 'Europe/Paris')) AS newest_date,
case
when TIME(convert_tz(date_cet, 'UTC', 'Europe/Paris')) between '00:00:00' and '05:59:59' then 3
when TIME(convert_tz(date_cet, 'UTC', 'Europe/Paris')) between '06:00:00' and '09:29:59' then 8
when TIME(convert_tz(date_cet, 'UTC', 'Europe/Paris')) between '09:30:00' and '12:29:59' then 11
when TIME(convert_tz(date_cet, 'UTC', 'Europe/Paris')) between '12:30:00' and '15:29:59' then 14
when TIME(convert_tz(date_cet, 'UTC', 'Europe/Paris')) between '15:30:00' and '18:29:59' then 17
when TIME(convert_tz(date_cet, 'UTC', 'Europe/Paris')) between '18:30:00' and '23:59:59' then 20
end as 'time_intervals'
FROM phonation_features
WHERE convert_tz(date_cet, 'UTC', 'Europe/Paris') >= CURRENT_TIMESTAMP() - interval 5000 DAY AND user_id = 5
GROUP BY time_intervals
ORDER BY time_intervals ASC
有没有办法使用生成变量GROUP BY
?
我想创建一个timestamp_timeZone
可以在所有查询中重复使用的变量。
这可能吗?
我需要生成一个 POST/查询,允许使用时区(→欧洲/雅典、→欧洲/布鲁塞尔、→欧洲/伦敦或→欧洲/巴黎。)发送有效载荷,并将响应更新的时间戳+时区。
根据给定的数据,我可以考虑创建一个自定义函数
'+00:00'
UTC 和UTC +1'+01:00'
在哪里。Europe/Paris
考虑以下数据,
该功能将作为:
https://dbfiddle.uk/g6rYOHbk
您的最终查询类似于:
编辑
该功能需要稍作修改。对于此要求,您需要两个输入变量,即日期和时区。
Europe/London --- UTC +1
https://dbfiddle.uk/a-OF8pxF
调用函数时需要提供两个参数,最终查询如下所示: