Jump to content

adding the values of two columns together


Justnew

Recommended Posts

I am trying to add a value to an existing value in the coumn by using the select statement

 

select tea, mango, pepper price + profit as price from products

 

the profit have a default value of 200. when I run the query I only get the value of the profit

Can someone help me out

Link to comment
https://forums.phpfreaks.com/topic/1413-adding-the-values-of-two-columns-together/
Share on other sites

Justnew, if you utilized either of my previous examples, the price column individually is non-existent. This is due to the fact that we have combined the values of the price and profit columns and then proceeded to alias that sum as total with the AS keyword. I do not recommend aliasing two columns with an original column name. To clarify why your previous method did not work is because the AS keyword is optional when aliasing a SELECT expression. So by not separating the pepper and price columns with a single coma you effectively aliased the pepper, price, and profit columns as price.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.