set @total:=0;
select id, name, value, `order`
from
(select
id, name, value, `order`,
@total:=if(@total is null, 0, @total)+`order` as total
from THE_TABLE
order by `order`
) as derived
where total<=30;
set @total:=0;
select id, name, value, `order`
from
(select
id, name, value, `order`,
@total:=if(@total is null, 0, @total)+`order` as total
from THE_TABLE
order by `order`
) as derived
where total<=30;