Jump to content

have " sum, count, group by " in 1 query


Recommended Posts

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 !

Link to comment
https://forums.phpfreaks.com/topic/167912-have-sum-count-group-by-in-1-query/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.