[thelist] php/mysql: fetch records posted this week and add values

Luther, Ron ron.luther at hp.com
Tue Oct 21 15:44:18 CDT 2003


Dunstan Orchard asked:

>>I need to write a query which selects only the records whose blog_date value
>>falls in this week.
>>I then need to get the sum of all the values of blog_num for those records.

Hi Dunstan,

You may have to look up the exact syntax in MySQL, but I believe it 
would be along the lines of:

Select SUM(blog_num) as SUMMER from blog 
WHERE blog_date BETWEEN '06-OCT-03' and '12-OCT-03';

The 'between' on the dates in the where clause restricts the query 
to acting on the records you are interested in.

Most databases have some kind of SUM(var) function to let you pull 
a summation.

HTH,

RonL.
(Most definately *not* stepping into the 'big guy's shoes.)



More information about the thelist mailing list