Jump to content


Photo

MySQL calculation


  • Please log in to reply
2 replies to this topic

#1 pjrat

pjrat
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 09 February 2003 - 10:24 PM

Hi

Trying to learn MysQL and have a calculation problem. I want a query to do the following example (all are floats with numbers to add) -

SELECT a+b+c+d+e AS result FROM table

The above obviously dosen\'t work, where, this line below does -

SELECT a+b AS result FROM table (and gives me the total of the two fields). Can I calculate all five fields somehow and create a result field?

Thanks in advance - Pat J

#2 pallevillesen

pallevillesen
  • Members
  • PipPipPip
  • Advanced Member
  • 135 posts
  • LocationDenmark

Posted 10 February 2003 - 11:25 AM

Well....

select 1+2+3+4+5 AS result;

does work fine enough....

So

select (a+b+c) as result from table;

should work as well.... check your syntax and if you are absolutely sure that there is something wrong, then please post some more info on tables and variables...

But you are using the correct syntax. It should work.

P.
Palle Villesen, www.birc.dk [br]Bioinformatics Research Center

#3 pjrat

pjrat
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 10 February 2003 - 11:43 AM

Hi (biopv)

Thanks for your answer, but I really made a silly mistake. One of the fields was NULL and this stopped it from running the query. Once I changed the field to NOT NULL and added a 0.0 default, it worked well.

Thanks, Pat.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users