Re: need some SQL help

From: howzat <dave_at_dave.net>
Date: Sat, 24 Dec 2005 18:23:18 GMT
Message-ID: <qmgrf.12239$f7.4015_at_newsfe3-win.ntli.net>


"Hugo Kornelis" <hugo_at_pe_NO_rFact.in_SPAM_fo> wrote in message

> The following is untested since I don't have MySQL. It *should* work on
> all ANSI-compliant databases. It should also take no more than one
> single pass over the data in the table (if the optimizer in your
> database is worth it's salt, that is).
>
> SELECT customer_id
> FROM (SELECT customer_id, order_type
> FROM orders
> WHERE order_type IN (3, 4)
> GROUP BY customer_id, order_type
> HAVING ( order_type = 3 AND SUM(amount) > 100)
> OR ( order_type = 4 AND SUM(amount) > 200) ) AS derived
> GROUP BY customer_id
> HAVING COUNT(*) = 2
>

hugo, it worked perfectly! Thanks for taking the time to help me. Much appreciated. Received on Sat Dec 24 2005 - 19:23:18 CET

Original text of this message