sql >> Base de Datos >  >> RDS >> Mysql

devolver filas donde la suma en un campo es menor que un valor dado

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;