UPDATE runner SET totals = (run + swim + bike)/60 WHERE name='jim'
I had to use the /60 to divide the minutes by 60 to get the hours
-----Original Message-----
From: Benjamin Pflugmann [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 06, 2001 6:13 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Adding fields
Hi.
On Fri, Jul 06, 2001 at 03:45:48PM -0600, [EMAIL PROTECTED] wrote:
>
> to many hours anyway I am struggling with what seems to be an easy task
but I am stuck.
>
> I am trying to total the fields with numbers (run + swim + bike) from a
racer name="joe"
> and insert the ammount into a field called totals in a table called
runner.
>
> UPDATE runner SET totals="SUM(run + swim + bike)" WHERE name="joe"
>
> Any hints
Start with the belonging SELECT:
mysql> SELECT "SUM(run + swim + bike)" FROM runner WHERE name="joe"
+------------------------+
| SUM(run + swim + bike) |
+------------------------+
| SUM(run + swim + bike) |
+------------------------+
which shows, that SUM() is not evaluated. How can this be? Because it
is a string. Everything within quotes is considered to be a string. So
drop these quotes.
The other thing is SUM() is a grouping function, i.e. it takes several
rows and sums up the expressions of all these rows. This is not what
you wish.
'+' works perfectly without any function around it. Just use
SELECT run + swim + bike FROM runner WHERE name="joe"
which should show the sum you want to write into 'totals'. Now the
UPDATE is an easy change:
UPDATE runner SET totals = run + swim + bike WHERE name="joe"
Starting with a belonging SELECT to the UPDATE one wants to perform is
always a good idea. It ensures that hte WHERE clause is correct, the
intended expression is correct and if you create the UPDATE from the
SELECT (with copy & paste or alike), you are safe of typos.
Bye,
Benjamin.
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php