Simao
Simao

Reputation: 591

Update null value on existing column/tables using aggregation

The formula would be something like this ( all those are values existing in the table ) :

Expected Profit = quantity * (1 - failure_rate) * expected_sales_price - (product_fixed_cost + young_product_cost_value)

Now I want to update it with SQL statement, but I dont really know how to do it :

UPDATE tablePlannedSales
SET expected_profit = (*SQL I should use to set the formula above*)
WHERE expected_profit IS NULL

Any help would be very welcome,

Upvotes: 0

Views: 74

Answers (1)

Jonas Metzler
Jonas Metzler

Reputation: 5975

In case all columns that you need within your formula are part of the table you want to update, it's not required do a select. You can just execute the update command according to your example:

UPDATE tablePlannedSales 
  SET expected_profit = quantity * (1 - failure_rate) * expected_sales_price - (product_fixed_cost + young_product_cost_value) 
WHERE expected_profit IS NULL

If this does not work as expected, something with your formula is wrong or some columns within the formula are not present in this table.

Upvotes: 1

Related Questions