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 Price of slno items 1 item 1 1000 2 items 2 2000 3 items 3 3000 4 items 4 4000 5 items 5 5000 6 items 6 6000

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

  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   

or

 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   

by order = 10000 is demo

Comments

Popular posts from this blog

python - how we can use ajax() in views.py in django? -

matlab - Using loops to get multiple values into a cell -

python - Sequence Pattern recognition with Pybrain -