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 mytable (
`Phrase` VARCHAR(8),
`qty` INTEGER
);

INSERT INTO mytable
(`Phrase`, `qty`)
VALUES
('phrase_1', '4'),
('phrase_1', '1'),
('phrase_1', '8'),
('phrase_2', '2'),
('phrase_3', '3'),
('phrase_3', '2');
SELECT phrase,total,(total - mi/ma - mi) AS rank
FROM
(SELECT phrase, sum(qty) as total
FROM mytable
GROUP By phrase
ORDER BY total DESC) t1 CROSS JOIN (SELECT MIN(total) mi,MAX(total) ma
FROM
(SELECT phrase, sum(qty) as total
FROM mytable
GROUP By phrase
ORDER BY total DESC) t1) t2


phrase total rank
phrase_1 13 10.8462
phrase_3 5 2.8462
phrase_2 2 -0.1538