mysql - SELECT * FROM table while condition=true? -


i want select table while 1 condition true,

select * (select * from`table1` `t1` order t1.date) `t2` while t2.id!=5 

when while condition comes false stop selecting next rows.

please me, have search lot , many similars in stackoverflow can't it.

please don't tell me where , want solution in sql not in php or other

ok real problem here

select *,(select sum(t2.amount) (select * transaction t1 order t1.date) `t2`) total_per_transition transaction  

here want calculate total balance on each transaction

first find first date condition fails, id=5:

select date  table1 id = 5  order date   limit 1 

then make above derived table (we call lim) , join original table rows previous dates: t.date < lim.date

select t.* table1 t   join   ( select date      table1     id = 5      order date       limit 1   ) lim     on t.date < coalesce(lim.date, '9999-12-31') ; 

the coalesce() case when there no rows @ id=5 - , in case want rows table.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -