Re: a mysql query stuck for the last week ......

From: Date: Wed, 21 May 2003 18:07:31 +0000
Subject: Re: a mysql query stuck for the last week ......
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-20024@lists.php.net to get a copy of this message
On Wed, 2003-05-21 at 14:37, toby z wrote: > if the above funct is right this query otta work:: > > > SELECT count(distinct tbl_chld_reg_400.chld_id) > from tbl_chld_reg_400 > where month(tbl_chld_reg_400.dom) = $loop_mon > and year(tbl_chld_reg_400.dom) = $yr > and ((DATE_FORMAT('tbl_chld_reg_400.dom', '%Y') - > DATE_FORMAT('tbl_chld_reg_400.dob', '%Y') > - (DATE_FORMAT('tbl_chld_reg_400.dom', '00-%m-%d') < > DATE_FORMAT('tbl_chld_reg_400.dob', '00-%m-%d'))) >=1) > > and ((DATE_FORMAT('tbl_chld_reg_400.dom', '%Y') - > DATE_FORMAT('tbl_chld_reg_400.dob', '%Y') > - (DATE_FORMAT('tbl_chld_reg_400.dom', '00-%m-%d') < > DATE_FORMAT('tbl_chld_reg_400.dob', '00-%m-%d'))) <=5) > and tbl_chld_reg_400.gndr='1' No... It won't. Take a look at this query for a short while: SELECT count(distinct tbl_chld_reg_400.chld_id) FROM tbl_child_reg_400 If you analyze the different parts of this query carefully, I think you will realize what the problem is. The thing is: both COUNT and DISTINCT are SQL functions, and functions *always* (just as in PHP) need to have () -- parantheses. So if you rewrite this very basic query to SELECT COUNT(DISTINCT(tbl_chld_reg_400.chld_id)) FROM tbl_chld_reg_400, you should get all unique child IDs. And then you can add your conditional as you wish. HTH. -- Best regards, Per Lundberg / Capio ApS Phone: +46-18-4186040 Fax: +46-18-4186049 Web: http://www.nobolt.com

Attachment: [application/pgp-signature] This is a digitally signed message part signature.asc
« previous php.windows (#20024) next »