-- setup
CREATE TABLE averages (val INTEGER);
INSERT INTO averages VALUES (1);
INSERT INTO averages VALUES (2);
INSERT INTO averages VALUES (3);
INSERT INTO averages VALUES (1);
INSERT INTO averages VALUES (2);
INSERT INTO averages VALUES (4);
INSERT INTO averages VALUES (2);
INSERT INTO averages VALUES (5);
INSERT INTO averages VALUES (2);
INSERT INTO averages VALUES (3);
INSERT INTO averages VALUES (3);
INSERT INTO averages VALUES (1);
INSERT INTO averages VALUES (3);
INSERT INTO averages VALUES (6);
-- find the mode
WITH
  counts AS
  (
    SELECT
      val,
      COUNT(*) AS num
    FROM
      averages
    GROUP BY
      val
  )
SELECT
  val AS mode_val
FROM
  counts
WHERE
  num IN (SELECT MAX(num) FROM counts);