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
| WITH Stock AS
(
select 'Toto' as mag, 'Lecteurs DVD' as eqp, 27 as qte from dual union all
select 'Toto' , 'Téléviseurs numériques', 45 from dual union all
select 'Toto' , 'Lave linge' , 29 from dual union all
select 'Toto' , 'Gazinières' , 14 from dual union all
select 'Toto' , 'Perçeuses' , 12 from dual union all
select 'Titi' , 'Gazinières' , 47 from dual union all
select 'Titi' , 'Perçeuses' , 24 from dual union all
select 'Titi' , 'Lave linge' , 13 from dual union all
select 'Tata' , 'Téléviseurs numériques', 26 from dual union all
select 'Tata' , 'Lave linge' , 15 from dual
)
SELECT
MAG,
CASE
WHEN EQP IN ('Téléviseurs numériques', 'Lecteurs DVD') THEN 'MULTIMEDIA'
WHEN EQP IN ('Gazinières', 'Lave linge') THEN 'ELECTROMENAGER'
WHEN EQP = 'Perçeuses' THEN 'OUTILS'
END AS GRP_EQP,
SUM(QTE) AS QTE_TOT
FROM
STOCK
GROUP BY
MAG,
CASE
WHEN EQP IN ('Téléviseurs numériques', 'Lecteurs DVD') THEN 'MULTIMEDIA'
WHEN EQP IN ('Gazinières', 'Lave linge') THEN 'ELECTROMENAGER'
WHEN EQP = 'Perçeuses' THEN 'OUTILS'
END
ORDER BY
MAG DESC,
GRP_EQP ASC;
MAG GRP_EQP QTE_TOT
------ ----------------- --------
Toto ELECTROMENAGER 43
Toto MULTIMEDIA 72
Toto OUTILS 12
Titi ELECTROMENAGER 60
Titi OUTILS 24
Tata ELECTROMENAGER 15
Tata MULTIMEDIA 26 |
Partager