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 Workout ( `Date` int, `User` int, `Distance` int, `Calories` int ); insert into Workout values (1614944833, 1, 100, 32), (1614944232, 2, 100, 43), (1624944831, 1, 150, 23), (1615944832, 3, 250, 63), (1614644836, 1, 500, 234), (1614954835, 2, 100, 55), (1614344834, 3, 100, 34), (1614964831, 1, 260, 23), (1614944238, 1, 200, 44); with comulative as ( select User, Distance, Calories, sum(Distance) over (partition by User order by Date) SumDistance, sum(Calories) over (partition by User order by Date) SumCalories from Workout order by User, Date ) select User, max(SumDistance), max(SumCalories) from comulative where SumDistance - Distance < 1000 group by User;

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

Copy Clear