Hi, I'm looking to optimize my query.
CREATE TEMPORARY TABLE table1
SELECT a
FROM (
SELECT
a
FROM my_table
WHERE DATE_ADD(my_table.`date`, INTERVAL -4 HOUR) >= DATE_FORMAT(NOW()- INTERVAL 6 HOUR, '%Y-%m-01 00:00:00')
) a
GROUP BY b ;
what this sql does is to get something from the begining of the month, where the day starts at 6am, and there is a 2 hour difference between db timezone and my location's actual time (interval -4). it doesn't really matter. just looking for a way to take this part "DATE_FORMAT(NOW()- INTERVAL 6 HOUR, '%Y-%m-01 00:00:00')" and replace it with "@x".
not sure how to do the SET @x = DATE_FORMAT(NOW()- INTERVAL 6 HOUR, '%Y-%m-01 00:00:00') function.