All pastes #475339 Raw Edit

nice

public sql v1 · immutable
·published 2007-05-07 11:52 UTC
rendered paste body
SELECThouse, AVG(salary) AS medianFROM (	SELECT	h.id as house,	x.salary	FROM	person x,	person y,	house h	WHERE	x.houseid=h.id AND	y.houseid=h.id	GROUP BY	x.salary, h.id	HAVING	(		(			SUM(SIGN(1-SIGN(y.salary-x.salary))))>=floor((COUNT(*)+1)/2		)	)	AND	(		(			SUM(SIGN(1+SIGN(y.salary-x.salary))))>=floor((COUNT(*)+1)/2		)	)	ORDER BY h.id) AS tmpGROUP BYhouse;