Re: Calculate a value during the SQL command
| From: | DL Neil | Date: | Sat, 09 Feb 2002 00:23:36 +0000 |
| Subject: | Re: Calculate a value during the SQL command | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-16741@lists.php.net to get a copy of this message | ||
John,
> I know I could very easily do this after doing the
> initial database call simply by calculating the two
> variables, but, I was wondering if there was a way to
> do this during the sql statement so my results would
> already have my answer...
>
> Here's the setup. I have two tables. Table A has the
> information about a mailing. Table B has an individual
> record for each click generated by the e-mail.
>
> They look like this:
>
> TableA
> ID // unique identifier
> mail_date
> mail_qty // shows how many mails were sent
>
>
> TableB
> ID // unique identifier
> mail_ID // matches up with the ID in Table A
> mem_ID // the member's unique code
>
> Here is what I thought was going to work (but didn't):
>
> SELECT mail_date, mail_qty, count(*) as clicks,
> ((clicks / mail_qty)*100) as percentage FROM TableA,
> TableB WHERE mail_ID = TableA.ID GROUP BY mail_ID
>
> What I was hoping to get back was something like this:
>
> | mail_date | mail_qty | clicks | percentage |
> | 2001-02-05 | 1000 | 100 | 10 |
>
> If I need to do this the long way, it's not a huge
> deal, but, I thought this may be something I could
> do...
>
> I hope I explained that good enough. Thanks for your
> help!
If the "clicks" is removed from the formula, and replaced with "count(*)" does
that solve the problem?
Let us know!
=dn