Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
create table tbl (date_time datetime, user_id int, price int); insert into tbl values ('2020-01-01 01:05:30', 1, 10), ('2020-01-01 02:45:33', 3, 20), ('2020-02-01 02:45:33', 3, 20), ('2020-03-25 11:10:15', 66, 10), ('2020-04-21 00:40:00', 21, 40), ('2020-04-22 15:00:00', 70, 30), ('2020-04-22 20:00:00', 21, 10); select DATE_FORMAT(date_time, "%Y-%m-%d %H") as date_time, count(distinct tbl.user_id), sum(tbl.price) #from ( #)dates from tbl GROUP BY DATE_FORMAT(date_time, "%Y-%m-%d %H") order by date_time;

Stuck with a problem? Got Error? Ask AI support!

Copy Clear