poe Posted July 29, 2009 Share Posted July 29, 2009 i have a table that look like this : LID HIT MTH TYPE 111 2 200712 R 222 2 200712 R 111 1 200712 R 222 1 200812 R 333 5 200812 R 444 1 200812 R 555 3 200812 R 111 2 200812 R 111 6 200904 F 444 1 200904 R 333 1 200904 F 111 5 200907 R 222 5 200907 R i want to count the number of links that: MTH > 200712 MTH < 200907 TYPE = 'R' SUM(HIT) > 3 so far i have SELECT * , sum(`HIT`) AS `TTL` FROM `STATS` WHERE `MTH` > 200712 AND `MTH` <= 200907 AND `TYPE` = 'R' AND `TTL` >3 GROUP BY `LID` now i am stuck ! Quote Link to comment https://forums.phpfreaks.com/topic/167912-have-sum-count-group-by-in-1-query/ Share on other sites More sharing options...
fenway Posted August 3, 2009 Share Posted August 3, 2009 Move the check for TTL > 3 to a HAVING clause -- the result isn't available until "after" the query runs. Quote Link to comment https://forums.phpfreaks.com/topic/167912-have-sum-count-group-by-in-1-query/#findComment-889943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.