mysql - Query to get all records until the sum of column less than or equal a value -
I want to get all records in a table, unless the sum of a particular column is less than or equal to 'N'. Ho .
For example:
Table: Data I want to get all the records from the table above until the amount (value) is less than or equal to 10000 So, with the table above My result will be the first 4 records. you can or by order = 10000 is demo
Select, item, price (select, item, value, @t: = @t + value increase from total table 1 (selection @t: = 0) I below the order) q Where the total & lt; = 10000
select
slno, item, price from (select slno, item, price, ( SELECT SUM price) Table 1 from which slno & lt; = t.slno) total from table 1) q where total & lt; Slno
Comments
Post a Comment