sql - Mysql search if last 3 records exist with same order -
i have table column of numbers
35 24 7 8 11 35 9 11 6 6 23 23 34 5 14 31 26 2 16 0 6 23 23
i want check if last 3 records
6 23 23
exist in previous records same order , result next number.
in example :
6 23 23
exist same order , result must : 34
assuming numbers ordered auto_incremented column named id
query should work:
select numbers vista id = ( select b.id + 3 ( select t1.id, t1.numbers t1val, t2.numbers t2val, t3.numbers t3val vista t1 join vista t2 on t1.id = t2.id-1 join vista t3 on t1.id = t3.id-2 t1.id = (select max(id) - 2 vista) ) join ( select t1.id, t1.numbers t1val, t2.numbers t2val, t3.numbers t3val vista t1 join vista t2 on t1.id = t2.id-1 join vista t3 on t1.id = t3.id-2 t1.id < (select max(id) - 2 vista) ) b on a.t1val = b.t1val , a.t2val = b.t2val , a.t3val = b.t3val , a.id <> b.id ) order id limit 1;
if id
column doesn't contain sequence can generate 1 appropriate row numbering query.
Comments
Post a Comment