[thelist] php/mysql: fetch records posted this week and add values
Marek Kilimajer
kilimajer at webglobe.sk
Tue Oct 21 17:29:12 CDT 2003
Hi, this is untested:
SELECT SUM(blog_num) FROM blog GROUP BY WEEK(blog_date) HAVING
WEEK(blog_date)=WEEK(NOW())
Dunstan Orchard wrote:
> Hi there,
>
> Just my luck, the day rudy decides to leave I get another MYSQL problem :o)
>
> Can anyone suggest how I can do the following:
>
> 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.
>
> For example:
>
> TABLE blog (
> blog_date date NOT NULL default '0000-00-00',
> blog_num tinyint(4) NOT NULL default '0'
> ) TYPE=MyISAM;
>
> 2003-11-15 23
> 2003-11-28 36
> 2003-12-08 16
> 2003-12-18 19
> 2003-12-20 35
> 2003-12-21 27
>
> The query would bring back:
>
> 2003-12-20 35
> 2003-12-21 27
>
> And then return the sum:
>
> 62
>
> Can anyone help? I'm stumped :o(
>
> Thanks very much - Dunstan
>
> ---------------------------
> Dorset, England
> http://www.1976design.com/
> http://www.1976design.com/blog/
More information about the thelist
mailing list