0

So I have a table with name, quantity and price

name        quantity        price        "custom-row"
a           12              5             12*5
b           20              3             20*3
c           18              10            18*10

Is it possible to add a "custom" row when using a select query? And I want the values in that row = quantity * price. How can I do that?

2 Answers 2

1
select name, quantity, price, (quantity * price) as custom_row
from table_name

you can just multiply your columns by column name and after AS sign any column name you want

Sign up to request clarification or add additional context in comments.

3 Comments

please write some text to your query
Why to use parentheses here?
@JonasMetzler sorry, but I'm used to it, because I have massive select's in queries in my job, it's easier for me to see. And less likely to make a mistake (2+2)*2=8 2+2*2=6
1

try this:

select name, quantity, price, quantity * price as custom-row
from table_name

you can where if needed filtering

2 Comments

your script will not work because, a middle dash in the custom column name -
If this should be an issue, the query you've shown is also incorrect since the question was "custom-row", not "custom_row". We can use quantity * price as 'custom-row', but I think the author of the question is able to set a valid alias on his/her own.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.