select - MySQL summing verses and n biggest results -
i've table looking more or less that:
**day** | **mileage** ---------------- 1 | 13 2 | 2 3 | 25 4 | 15 5 | 20 6 | 8 7 | 17 8 | 12 9 | 16 10 | 5
how write sql query:
- returning total mileage firts nth day without using php? example, day 1:13, day 2: 15, day 3: 40.
- how 5 biggest mileages without using limit?
for sum up:
select mday, (select sum(miles) mm s s.mday <= mm.mday) tot_miles mm;
for 5 biggest mileage per day
select mday, miles mm order miles desc limit 5
change column names , table name match yours.
since added "no use of limit", odd, can try this:
set @r =0; select * ( select *, @r :=@r+1 r mm order miles desc) e r<=5
Comments
Post a Comment