By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE tablename (`students` TEXT, `grades` REAL);
✓
INSERT INTO tablename (`students`, `grades`) VALUES
('Nick', '34'),
('Nick', '42'),
('Nick', '86'),
('Nick', Null),
('John', '38'),
('John', '12'),
('John', '74'),
('John', Null),
('Colin', '87'),
('Colin', '23'),
('Colin', '46'),
('Colin', '42');
✓
UPDATE tablename AS t1
SET grades = (
SELECT ROUND(AVG(t2.grades), 1)
FROM tablename AS t2
WHERE t2.students = t1.students
)
WHERE t1.grades IS NULL;
✓
SELECT * FROM tablename;
students | grades |
---|---|
Nick | 34 |
Nick | 42 |
Nick | 86 |
Nick | 54 |
John | 38 |
John | 12 |
John | 74 |
John | 41.3 |
Colin | 87 |
Colin | 23 |
Colin | 46 |
Colin | 42 |