I have a table in MySQL with following structure.
CREATE TABLE MyTable (id CHAR(10), name CHAR(10), price INT, cat INT, size INT);
INSERT INTO MyTable (id, name, price, cat, size)
VALUES ('2065511307', 'abc', 2449, 1, 600),
('65fH72', 'bcd', 4395, 1, 851),
('65fH72', 'bcd', 4995, 2, 985),
('65fH72', 'bcd', 4678, 1, 865);
I am calculating aggregate values using functions like AVG, however, I'd like to calculate the Median instead.
How do I modify the following query to get median instead of mean?
SELECT id, cat, AVG(price) AS avg_price, AVG(size) AS avg_size
FROM MyTable
GROUP BY id, cat
HAVING avg_price <= 10000
The median will be calculated for price and size columns for each group.