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
|
WITH CPT AS
( SELECT SUBSTR(NUMERO,1,5) ACC_5,DEBIT DEB_ACC_5,CREDIT CR_ACC_5 ,
SUBSTR(NUMERO,1,4) ACC_4,SUM(DEBIT) OVER(PARTITION BY SUBSTR(NUMERO,1,4))DEB_ACC_4 ,
SUM(CREDIT)OVER(PARTITION BY SUBSTR(NUMERO,1,4)) CR_ACC_4,
SUBSTR(NUMERO,1,3) ACC_3 ,SUM(DEBIT) OVER(PARTITION BY SUBSTR(NUMERO,1,3))DEB_ACC_3 ,
SUM(CREDIT)OVER(PARTITION BY SUBSTR(NUMERO,1,3)) CR_ACC_3,
SUBSTR(NUMERO,1,2) ACC_2,SUM(DEBIT) OVER(PARTITION BY SUBSTR(NUMERO,1,2)) DEB_ACC_2,
SUM(CREDIT) OVER(PARTITION BY SUBSTR(NUMERO,1,2))CR_ACC_2,
SUBSTR(NUMERO,1,1) ACC_1 ,SUM(DEBIT) OVER(PARTITION BY SUBSTR(NUMERO,1,1))DEB_ACC_1,
SUM(CREDIT) OVER(PARTITION BY SUBSTR(NUMERO,1,1)) CR_ACC_1 ,
SUBSTR(NUMERO,1,1) ACC_ID1,SUBSTR(NUMERO,2,1) ACC_ID2,SUBSTR(NUMERO,3,1) ACC_ID3,
SUBSTR(NUMERO,4,1) ACC_ID4,SUBSTR(NUMERO,5,1) ACC_ID5 FROM COMPTE)
SELECT DISTINCT ACC_5 ,DEB_ACC_5,CR_ACC_5, ACC_ID1, ACC_ID2, ACC_ID3, ACC_ID4, ACC_ID5
FROM CPT
UNION ALL
SELECT DISTINCT ACC_4 ,DEB_ACC_4,CR_ACC_4, ACC_ID1, ACC_ID2, ACC_ID3, ACC_ID4,NULL ACC_ID5
FROM CPT
UNION ALL
SELECT DISTINCT ACC_3 , DEB_ACC_3 , CR_ACC_3,ACC_ID1, ACC_ID2, ACC_ID3,NULL ACC_ID4,NULL ACC_ID5
FROM CPT
UNION ALL
SELECT DISTINCT ACC_2 , DEB_ACC_2 , CR_ACC_2 , ACC_ID1, ACC_ID2,NULL ACC_ID3,NULL ACC_ID4,NULL ACC_ID5
FROM CPT
UNION ALL
SELECT DISTINCT ACC_1 , DEB_ACC_1 ,CR_ACC_1 , ACC_ID1,NULL ACC_ID2,NULL ACC_ID3,NULL ACC_ID4,NULL ACC_ID5
FROM CPT
ORDER BY ACC_ID1, ACC_ID2, ACC_ID3, ACC_ID4,ACC_ID5 |
Partager