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

Hassan Schroeder hassan at webtuitive.com
Tue Oct 21 16:09:32 CDT 2003


Dunstan Orchard wrote:

> 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.

> 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

SELECT SUM(blog_num) FROM blog WHERE -- eh? Does "in this week" mean
the last seven days, or since Monday, or since Friday, or??

And is it really almost Christmas in Dorset?  :-)

-- 
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design ===  (+1) 408-938-0567   === http://webtuitive.com

                           dream.  code.





More information about the thelist mailing list