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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| select c1
, sum ( case when nat in ( 4, 1) then decode(cru,'cru1',t1qb,0)
when nat in (10,15) then decode(cru,'cru1',t2qb,0)
else null
end ) cru1
, sum ( case when nat in ( 4, 1) then decode(cru,'cru2',t1qb,0)
when nat in (10,15) then decode(cru,'cru2',t2qb,0)
else null
end ) cru2
, sum ( case when nat in ( 4, 1) then decode(cru,'cru3',t3qb,0)
when nat in (10,15) then decode(cru,'cru3',t3qb,0)
else null
end ) cru3
, sum ( case when nat in ( 4, 1) then decode(cru,'cru4',t1qb,0)
when nat in (10,15) then decode(cru,'cru4',t2qb,0)
else null
end ) cru4
, sum ( case when nat in ( 4, 1) then t1qb,
when nat in (10,15) then t2qb
else null
end ) total
from ( select case when t3.nat in ( 4, 10) then 'nouveau'
when t3.nat in ( 1, 15) then 'ancien'
else null
end c1
, t1.qtebase t1qb
, t2.qtebase t2qb
, t3.cru cru
, t3.nat nat
from t1 inner join
t2 on t1.cru=t2.cru inner join
t3 on t1.cru=t3.cru ) t
group by c1
union all
select c1
, sum ( case when nat in ( 4, 1) then decode(cru,'cru1',t1qb,0)
when nat in (10,15) then decode(cru,'cru1',t2qb,0)
else null
end ) cru1
, sum ( case when nat in ( 4, 1) then decode(cru,'cru2',t1qb,0)
when nat in (10,15) then decode(cru,'cru2',t2qb,0)
else null
end ) cru2
, sum ( case when nat in ( 4, 1) then decode(cru,'cru3',t3qb,0)
when nat in (10,15) then decode(cru,'cru3',t3qb,0)
else null
end ) cru3
, sum ( case when nat in ( 4, 1) then decode(cru,'cru4',t1qb,0)
when nat in (10,15) then decode(cru,'cru4',t2qb,0)
else null
end ) cru4
, sum ( case when nat in ( 4, 1) then t1qb,
when nat in (10,15) then t2qb
else null
end ) total
from ( select 'total' c1
, t1.qtebase t1qb
, t2.qtebase t2qb
, t3.cru cru
, t3.nat nat
from t1 inner join
t2 on t1.cru=t2.cru inner join
t3 on t1.cru=t3.cru ) t
group by c1; |
Partager