sqlyog - How to query and group every continuous number series in MySQL? -


i have freight.or_nos table contains series of receipt numbers. want list or's being issued excluding status='cancelled' making series broken in groups. example have receipt stab 125001-125050, , 125020 cancelled listing result be:

+-------------------------------------------------------+ |  or start  |    or end    |   quantity   |   amount   | +-------------------------------------------------------+ | 125001     | 125019       |           19 |            | +-------------------------------------------------------+ | 125021     | 125050       |           30 |            | +-------------------------------------------------------+ 

this seems tough query.

thanks reading made it, now! :) here's query(disregard other characters it's form our cgi):

{.while select `start`,`end`,or_prefix,or_suffix,sum(a.amount) g_total,count(*) qcount (select l.id `start`,( select min(a.id) id ( select a.or_no id freight.`or_nos` a.status!='cancelled' , a.log_user = 0@user_teller , date(a.or_date)='@user_date`date'  , if(a.status='default' , a.amount=0,0,1)  ) left outer join ( select a.or_no id freight.`or_nos` a.status!='cancelled' , a.log_user = 0@user_teller , date(a.or_date)='@user_date`date'  , if(a.status='default' , a.amount=0,0,1)    ) b on a.id = b.id - 1 b.id null , a.id >= l.id ) `end` ( select a.or_no id freight.`or_nos` a.status!='cancelled' , a.log_user = 0@user_teller , date(a.or_date)='@user_date`date' , if(a.status='default' , a.amount=0,0,1)  ) l left outer join ( select a.or_no id freight.`or_nos` a.log_user = 0@user_teller , date(a.or_date)='@user_date`date' , if(a.status='default' , a.amount=0,0,1)  )  r on r.id = l.id - 1 r.id null) k left join freight.`or_nos` on a.`or_no` between k.start , k.end  , date(a.`or_date`)='@user_date`date' , a.log_user =0@user_teller , if(a.status='default' , a.amount=0,0,1) , a.status!='cancelled' group `start`}           {.start}{.x.24.12:end}{.x`p0.40.-5:qcount}{.x`p2.57.-15:g_total}{.asc 255} {.wend}{.asc 255} 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -