Q:

MYSQL Updating database using maths?

My query: 
UPDATE `settings_products` SET `stock_osrs` = SUM(stock_osrs - 50)

I have a stock system in my admin panel which currently displays stock levels set by the admins, but I am creating an API so every payment that has been completed will take away the stock.
Lets say that the ordered amount is "50" like in the query and I want to take this away from the stock_osrs.
How exactly would I go about doing this?
EDIT: I am aware that I could use PHP to do the calculations and then update the table from that, but I feel this will be less reliable as I would have to do "50,000" - 50 = "45,950" and post that number to the database.
In this time there could have been another order which would cause the code to mess up, hence that I need to use SQL to achieve this!

A:

UPDATE `settings_products` SET `stock_osrs` = `stock_osrs` - 50

SUM() operates on groups of records - e.g., SELECT SUM(stock_osrs) FROM settings_products WHERE... would give you the total of stock_osrs for a group of records. It is possible to use SUM() as well - e.g., to get the SUM() of records in one table and store it in a field in another table, but that gets a bit more complicated. For simple inside-one-record math, just include the equation. You can even include multiple fields - e.g., UPDATE inventory SET available = onhand - onorder or similar statements.

