Jump to content

Archived

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

Justnew

adding the values of two columns together

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

Share this post


Link to post
Share on other sites

Method no.1

 

SELECT tea, mango, pepper, price + profit AS total FROM products

 

Method no.2

 

SELECT tea, mango, pepper, (price + profit) AS total FROM products

Share this post


Link to post
Share on other sites

Thank you for your reply I have tried the code but the price column becomes blank no values is desplayed under the column name Price

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.