Jump to content

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.