| 12
 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
 
 |  
with aa as (
SELECT code_SEGMENT,count(*) sss,
case when MNT        >0 AND MNT_REVENU<=500 then  '0_500'
      when MNT >500 AND MNT_REVENU<=1000 then   '500_1000'
     when MNT >1000 AND MNT_REVENU<=1500 then  '1000_1500' 
     when MNT >1500 AND MNT_REVENU<=2000  then '1500_2000'
     when MNT >2000 AND MNT_REVENU<=3000 then  '2000_3000'
       when MNT >3000 AND MNT_REVENU<=4000 then  '3000_4000'
      when MNT >4000 AND MNT_REVENU<=5000 then  '4000_5000'
      when MNT >5000 AND MNT_REVENU<=7000   then  '5000_7000'
     when MNT >7000 AND MNT_REVENU<=10000 then  '7000_10000'
    when MNT >10000  then  'superieur_10000'
     end cas 
 
FROM D_revenue p
 
where COD_SEGMENT in (0,1,2,3,4)
group by CODe_SEGMENT,
 
case when MNT        >0 AND MNT_REVENU<=500 then  '0_500'
      when MNT >500 AND MNT_REVENU<=1000 then   '500_1000'
     when MNT >1000 AND MNT_REVENU<=1500 then  '1000_1500' 
     when MNT >1500 AND MNT_REVENU<=2000  then '1500_2000'
     when MNT >2000 AND MNT_REVENU<=3000 then  '2000_3000'
       when MNT >3000 AND MNT_REVENU<=4000 then  '3000_4000'
      when MNT >4000 AND MNT_REVENU<=5000 then  '4000_5000'
      when MNT >5000 AND MNT_REVENU<=7000   then  '5000_7000'
     when MNT >7000 AND MNT_REVENU<=10000 then  '7000_10000'
    when MNT >10000  then  'superieur_10000'
     end 
 
)
select cas,
 
(select sum(sss)  from aa where CODe_SEGMENT in (3,4) group by cas) as 'segment_3-4',
(select sum(sss) from aa where CODe_SEGMENT in (0,1,2) group by cas) as 'segment_0_1_2'
 
 
from aa | 
Partager