• Advertisement
Sign in to follow this  

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

This topic is 4159 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Share this post


Link to post
Share on other sites
Advertisement
You'll need to use a HAVING clause for that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
You'll need to use a HAVING clause for that.


Oh, yeah. Duh. Thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement