So I have a table like:
Games Won | Games Lost | XP
11 | 3 |
but is there a way to do like math in MySQL so XP = (Games Won X 10) - (Games Lost X -5)
or does it have to be done in php then updated?
Cheers
MySQL math?
Moderator: General Moderators
Re: MySQL math?
update `table` set `xp` = (games_won * 10) - (games_lost * 5)
Re: MySQL math?
As Darhazer said, you can include simple computation in SQL statements, but be warned that in most circumstances you should be storing raw data in a database and making calculations when you retrieve the data. For a particular, very specific application, it will often work to store these calculated values, but for more useful databases, you usually will not be able to predict what you or someone else may want to do with the data in the future, so rather than storing manipulated data, you should nearly always design it to store the basic raw data. You can always apply whatever factors you want when you retrieve the data later, but the real original data is what will remain stored in the database.
Re: MySQL math?
Appreciate the help and tips, thanks
Dom
Dom