How to group data by selected ti,e slice?
Briefly

How to group data by selected ti,e slice?
"SELECT HOUR(o_time) AS hour, SUM(profit) AS hour_profit FROM data WHERE DATE(`o_time`) BETWEEN :start_date AND :end_date AND TIME(`o_time`) BETWEEN :hour_start AND :hour_end AND WEEKDAY(`o_time`) IN ($days) AND hideshow = 'hide' AND user_id = :user_id AND `item` = :item GROUP BY HOUR ORDER BY HOUR"
"How do I chane the GROUP BY HOUR SO THE INSTEAD OF HOUR THERE WILL BE A VARIABLE WHCH WILL GROUP data BY 5min, 10Min, 15min, 30min, 1 hour, 4hours, while the time section is selected by the user and passed to the function as the variable ?"
"How can hour be 10min, 30min etc? I don't get it"
Compute a numeric bucket index by dividing UNIX_TIMESTAMP(o_time) by an interval length in seconds and applying FLOOR. Convert the bucket index back to a readable period start with FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(o_time)/interval_seconds)*interval_seconds). Use that expression in SELECT and GROUP BY to aggregate profits per bucket. Set interval_seconds = minutes * 60 (e.g., 5min=300, 1h=3600, 4h=14400). Pass the chosen interval from PHP as an integer to the query or compute it in PHP and inject safely. Be mindful of timezone behavior and use CONVERT_TZ if needed.
[
|
]