Jump to content

Recommended Posts

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? 

Link to comment
https://forums.phpfreaks.com/topic/148540-solved-finding-the-sum-of-a-subset/
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.