MySQL中的CONCAT()

时间:2015-12-22 11:27:28

标签: mysql concat

我需要像SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr') AS creditdAmount FROM transaction; 这样的输出,我试过这个:

500000

但我只获得Id CreditAmount DebitAmount Transactiondate -- ------------ ----------- --------------- 1 100000 0 2015-12-08 2 100000 5000 2015-12-08 3 100000 2000 2015-12-08 4 100000 3000 2015-12-08 5 100000 5000 2015-12-08

表格结构:

ActiveRecord

3 个答案:

答案 0 :(得分:2)

请检查以下内容。这对你来说是值得的:

SELECT 
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount 
FROM transactioninfo

答案 1 :(得分:1)

您可以尝试将您的值作为varchar进行CAST,然后尝试这样:

SELECT  CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;

答案 2 :(得分:0)

您可以使用此查询

 SELECT concat(creditdAmount,' (Cr)') FROM  
   (  
    SELECT SUM(id) AS creditdAmount FROM transaction  
   )as temp;