Re: Need help on using Median on more than one column

-- Cross Joined for normalization
CREATE TABLE OneToFour(i INT);
INSERT INTO OneToFour(1);
INSERT INTO OneToFour(2);
INSERT INTO OneToFour(3);
INSERT INTO OneToFour(4);
SELECT id, Avg(val)
FROM
(
SELECT
id
,CASE i -- normalize columns to rows
WHEN 1 THEN c1
WHEN 2 THEN c2
WHEN 3 THEN c3
WHEN 4 THEN c4
END AS val
FROM vt CROSS JOIN OneToFour
QUALIFY Row_Number() Over (PARTITION BY id ORDER BY val) BETWEEN 2 AND 3
) AS dt
GROUP BY id

Re: Need help on using Median on more than one column

-- Cross Joined for normalization
CREATE TABLE OneToFour(i INT);
INSERT INTO OneToFour(1);
INSERT INTO OneToFour(2);
INSERT INTO OneToFour(3);
INSERT INTO OneToFour(4);
SELECT id, Avg(val)
FROM
(
SELECT
id
,CASE i -- normalize columns to rows
WHEN 1 THEN c1
WHEN 2 THEN c2
WHEN 3 THEN c3
WHEN 4 THEN c4
END AS val
FROM vt CROSS JOIN OneToFour
QUALIFY Row_Number() Over (PARTITION BY id ORDER BY val) BETWEEN 2 AND 3
) AS dt
GROUP BY id