All pastes #594049 Raw Edit

snoyes

public text v1 · immutable
#594049 ·published 2007-06-28 18:39 UTC
rendered paste body
SELECT customer FROM (
	SELECT 
		*
	FROM
		products
		JOIN (
			SELECT t1.customer, t1.date, COUNT(t2.customer) AS theCount
			FROM products t1
			LEFT JOIN products t2 ON t1.customer = t2.customer AND t1.date < t2.date
			GROUP BY t1.customer, t1.date
			HAVING theCount < 3
		) AS dt USING (customer, date)
	HAVING product = 50
) AS dt
GROUP BY customer
HAVING COUNT(*) = 3;