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
| With MaTable (id, article, prix, modepaiement) as
(
select 1, 'Chaise', 10, 'CHQ' union all
select 2, 'Chaise', 20, 'ESP' union all
select 3, 'Chaise', 60, 'ESP' union all
select 4, 'Table_', 100, 'ESP' union all
select 5, 'Table_', 120, 'CHQ' union all
select 6, 'Table_', 200, 'CHQ'
)
select article
, sum(prix) as prix
, coalesce(modepaiement, 'ALL') as modepaiement
from MaTable
group by article
, rollup(modepaiement, prix)
having GROUPING(prix) = 0
or GROUPING(modepaiement) = 1
order by MAX(id) asc;
article prix modepaiement
------- ----------- ------------
Chaise 10 CHQ
Chaise 20 ESP
Chaise 60 ESP
Chaise 90 ALL
Table_ 100 ESP
Table_ 120 CHQ
Table_ 200 CHQ
Table_ 420 ALL |