Last Updated: February 10, 2021
·
21
· kalinin84

Statistics (MariaDB)

CREATE TABLE scores (
    id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
    document_id INT UNSIGNED NOT NULL,
    score INT UNSIGNED NOT NULL
) ENGINE=InnoDB;
INSERT INTO scores (document_id, score) VALUES 
(1, 11),
(2, 18),
(2, 22),
(4, 36),
(5, 4),
(2, 6),
(4, 7),
(4, 8),
(5, 11),
(6, 22),
(7, 33),
(3, 46);
SELECT 
    document_id, 
    MIN(score),
    AVG(score),
    MAX(score),
    STD(score)
FROM scores
GROUP BY document_id
ORDER BY document_id DESC;