Re: need some SQL help
- From: "howzat" <dave@xxxxxxxx>
- Date: Sat, 24 Dec 2005 18:23:18 GMT
"Hugo Kornelis" <hugo@xxxxxxxxxxxxxxxxxxxxxx> 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.
.
- References:
- need some SQL help
- From: howzat
- Re: need some SQL help
- From: Hugo Kornelis
- need some SQL help
- Prev by Date: Re: SQL Query Question.
- Next by Date: Re: OID's vs Relational Keys?
- Previous by thread: Re: need some SQL help
- Next by thread: Re: need some SQL help
- Index(es):