clear markdown compare help best fiddles feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3601446 fiddles created (47981 in the last week).

CREATE TABLE tbl (name text, "2010" int, "2011" int, "2012" int, "2013" int); INSERT INTO tbl VALUES ('A', 10, null, 40, 50), ('B', 10, 20, 30, 60), ('C', 5, null, null, 5), ('D', 10, 20, null, null);
4 rows affected
 hidden batch(es)


SELECT (COALESCE("2010", 0) + COALESCE("2011", 0) + COALESCE("2012", 0)) / num_nonnulls("2010","2011","2012") AS avg FROM tbl t;
avg
25
20
5
15
 hidden batch(es)