I have these functional queries where I need to change timestamp in UTC to timestamp with different time zones
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
The only way I reach to work with my queries is using CONVERT_TZ()
as below:
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
Is there a way to generate a variable using GROUP BY
?
I would like to create a variable timestamp_timeZone
where I can reuse in all my queries.
Is this possible?
I need to generate a POST/query that allows to send a payload with the timeZone(→Europe/Athens, →Europe/Brussels, →Europe/London or →Europe/Paris.) and will responde the updated timestamsp+timezone.
4*round(time_to_sec(time(tt))/(4*3600))