add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table tmp_creances_clients
( annee integer
, montant_facture real
);

insert into tmp_creances_clients (annee, montant_facture) values
(2022, 7654.82),
(2021, 1518.95),
(2020, 18218.39),
(2019, 165744.34),
(2018, 46991.41),
(2017, 76701.13),
(2016, 447148.53),
(2015, 17713.54),
(2014, 17713.54),
(2000, 159766.95),
(1999, 6558.68),
(1998, 1031.14);

with cte_exercice (exercice, montant_facture) as
(
select max(annee, max(annee) over() -4)
, montant_facture
from tmp_creances_clients
)
select exercice
, round(sum(montant_facture), 2) as montant_an
, round(100 * sum(montant_facture) / sum(sum(montant_facture)) over(), 2) as taux
from cte_exercice
group by exercice
order by exercice desc;
exercice montant_an taux
2022 7654.82 0.79
2021 1518.95 0.16
2020 18218.39 1.88
2019 165744.34 17.14
2018 773624.92 80.02