1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| select count(distinct C.FID) AS C from
(
select distinct a.NUM, a.EID, a.FID, a.TP as TP1, b.TP as TP2, a.TVD as TVD1, b.TVD as TVD2
from
(select distinct
t6.ID as EID, t4.NUM, t1.ID, t1.SMI, t1.RVD, t2.TSI, t3.TP, t3.TVD, t2.FID
from TABLE1 t1
inner join TABLE2 t2 on t1.SMI = t2.ID
inner join TABLE3 t3 on t1.RVD = t3.ID
inner join TABLE4 t4 on t2.FID = t4.ID
inner join TABLE5 t5 on t4.SSI = t5.ID
left join TABLE6 t6 on t6.ID = t5.EID
where t2.TSI = 0
) a
full join
(select distinct
t6.ID as EID, t4.NUM, t1.ID, t1.SMI, t1.RVD, t2.TSI, t3.TP, t3.TVD, t2.FID
from TABLE1 t1
inner join TABLE2 t2 on t1.SMI = t2.ID
inner join TABLE3 t3 on t1.RVD = t3.ID
inner join TABLE4 t4 on t2.FID = t4.ID
inner join TABLE5 t5 on t4.SSI = t5.ID
left join TABLE6 t6 on t6.ID = t5.EID
where t2.TSI = 1
) b
on a.EID = b.EID and a.FID = b.FID
where a.TP = b.TP and a.RVD <> b.RVD
) AS C WHERE C.EID = 1234 |
Partager