0

I am having this SQL command:

Select company, purchases.stock,SUM(ammount)*price from purchases INNER JOIN curstock ON purchases.stock = curstock.stock Group by company , purchases.stock;

Which returns following table :

enter image description here

Is it possible that it would print instead of table strings like: "Company XXX owns YYY in ZZZ stock."

or SQL does not provide such formatting and it has to be done in code.

1 Answer 1

4

You can use CONCAT() function

SELECT CONCAT('Company ', company, ' owns ', SUM(ammount)*price, ' in ', purchases.stock, ' stock.') AS value
  FROM purchases 
 INNER JOIN curstock 
    ON purchases.stock = curstock.stock 
 GROUP BY company , purchases.stock;
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks , this is exactly what I was looking for. This function is specific to MYSQL tho isn't it? (Not that it would be problem because it is one I am using right now.)
Yes it is. CONCAT() function in MySQL automatically converts numbers to string so no need to convert them as oppose to MS SQL or Oracle which needs to use CAST() or TO_CHAR() respectively.
Is there also any option doing this in OPENSQL standard? that you know of?
I think ABAP OpenSQL also has CONCAT() function.
@LAS He is using MySQL as tagged in his question.

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.