By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE votes (
`id` INTEGER,
`video` INTEGER,
`rate` INTEGER
);
INSERT INTO votes
(`id`, `video`, `rate`)
VALUES
('0', '1', '8'),
('1', '1', '9'),
('2', '2', '6'),
('3', '3', '4');
SELECT video,
SUM(rate),
COUNT(*) AS "# votes",
(SELECT COUNT(*) FROM votes) Total_votes
FROM votes
GROUP BY video
video | SUM(rate) | # votes | Total_votes |
---|---|---|---|
1 | 17 | 2 | 4 |
2 | 6 | 1 | 4 |
3 | 4 | 1 | 4 |