我有这个SQL命令:
Select company, purchases.stock,SUM(ammount)*price from purchases INNER JOIN curstock ON purchases.stock = curstock.stock Group by company , purchases.stock;
返回下表:
是否可能打印而不是表格字符串,如: " XXX公司在ZZZ股票中拥有YYY。"
或SQL不提供此类格式,必须在代码中完成。
答案 0 :(得分:4)
您可以使用CONCAT()函数
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;