[web] [MySQL4] Doing a "where" after a "group by"

Started by
1 comment, last by BeanDog 17 years, 6 months ago
I've got a query that looks something like this: select person.*, sum(item.amount) as Total from person inner join item on item.personid = person.personid group by person.personid This sums up the total number of items for each person and returns it alongside the person record. What I want to do is something like this: select person.*, sum(item.amount) as Total from person inner join item on item.personid = person.personid group by person.personid where Total > 100 The problem is, I can't filter by aggregate fields. I'm using MySQL 4, so I can't use a subquery to get the job done. I have to do this in MySQL rather than manually in my PHP because I intend to do paging with "limit". How would I get this done?
Advertisement
You'll need to use a HAVING clause for that.
Quote:Original post by Sneftel
You'll need to use a HAVING clause for that.


Oh, yeah. Duh. Thanks.

This topic is closed to new replies.

Advertisement