I get a table with the following query
select k.sifrakolo as Id,j.jb1,d.jb2,t.jb3,c.jb4,p.jb5,s.jb6
from
kolo k,jedan j, dva d, tri t, cetiri c, pet p, sest s
where
k.b1 = j.b1 and
k.b2 = d.b2 and
k.b3 = t.b3 and
k.b4 = c.b4 and
k.b5 = p.b5 and
k.b6 = s.b6
How do I use query to get 3 same tables t1,t2,t3 with
t2 = t1.id -1 and
t3 = t1.Id -2
and compare data in t1 and t2 as p1 and
compare data in t1 and t3 as p2 as follows
SELECT
cast(case when t1.jb1 = t2.jb1 then '1' else '0' end as int)+
cast(case when t1.jb2 = t2.jb2 then '1' else '0' end as int)+
cast(case when t1.jb3 = t2.jb3 then '1' else '0' end as int)+
cast(case when t1.jb4 = t2.jb4 then '1' else '0' end as int)+
cast(case when t1.jb5 = t2.jb5 then '1' else '0' end as int)+
cast(case when t1.jb6 = t2.jb6 then '1' else '0' end as int)as p1,
cast(case when t1.jb1 = t3.jb1 then '1' else '0' end as int)+
cast(case when t1.jb2 = t3.jb2 then '1' else '0' end as int)+
cast(case when t1.jb3 = t3.jb3 then '1' else '0' end as int)+
cast(case when t1.jb4 = t3.jb4 then '1' else '0' end as int)+
cast(case when t1.jb5 = t3.jb5 then '1' else '0' end as int)+
cast(case when t1.jb6 = t3.jb6 then '1' else '0' end as int)as p2
order by t1.sifrakolo desc