By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE t
(id int auto_increment Primary Key,Groupe varchar(1), Count int)
;
INSERT INTO t
(Groupe, Count)
VALUES
('A', 22)
;
INSERT INTO t
(Groupe, Count)
VALUES
('B', 12);
INSERT INTO t
(Groupe, Count)
VALUES
('A', 10)
;
INSERT INTO t
(Groupe, Count)
VALUES
('B', 16)
;
select
Groupe,
count,
Total,
DENSE_RANK() over( order by Total desc ) as "Order"
from
(
select
id,
Groupe,
Count
, sum(Count) over(partition by Groupe) as Total
from t
) a
ORDER BY id
Groupe | count | Total | Order |
---|---|---|---|
A | 22 | 32 | 1 |
B | 12 | 28 | 2 |
A | 10 | 32 | 1 |
B | 16 | 28 | 2 |