eh270 Posted March 9, 2009 Share Posted March 9, 2009 This is probably pretty basic, but I am having a tough time with this: I have a database that has a few hundred rows of data about a mailing IP address. Each row has the IP it pertains to, the date of the reported data, and 20 or so fields that are consistent from day to day. The data arrives with inconsistent frequency, so it's possible the most recent row's date could be two or three days old. I'd like to structure a query that will take the last 30 rows worth of data and retrieve a sum for certain columns. I figured I'd just try to limit the results to the 30 most recent dates, and select the field as a sum... but when i query to obtain volume figures in this fashion, it gives me a sum for all the rows, not just the last 30: SELECT sum(volume), ip_address FROM `data` WHERE ip_address = "255.255.255.0" ORDER BY date DESC LIMIT 30; I'm sure this is a no brainer. Can someone help me out? Quote Link to comment https://forums.phpfreaks.com/topic/148540-solved-finding-the-sum-of-a-subset/ Share on other sites More sharing options...
eh270 Posted March 9, 2009 Author Share Posted March 9, 2009 I think I figured it out. For anyone who needs help with this, check out this page: http://forums.mysql.com/read.php?10,105508,105543#msg-105543 Quote Link to comment https://forums.phpfreaks.com/topic/148540-solved-finding-the-sum-of-a-subset/#findComment-780028 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.