MySQL 中的 CONCAT()
CONCAT() in MySQL
我需要像 500000 (Cr)
这样的输出,我试过这个:
SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr')
AS creditdAmount FROM transaction;
但我只得到 500000
。
Table结构:
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
您可以尝试将您的值转换为 varchar,然后像这样尝试:
SELECT CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;
你可以使用这个查询
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
请检查以下内容。这对你来说是值得的:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo
我需要像 500000 (Cr)
这样的输出,我试过这个:
SELECT CONCAT(SUM(transactioninfo.CreditAmount),'Cr')
AS creditdAmount FROM transaction;
但我只得到 500000
。
Table结构:
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
您可以尝试将您的值转换为 varchar,然后像这样尝试:
SELECT CONCAT(CAST(SUM(transactioninfo.CreditAmount) AS char(20)),' (Cr)') AS creditdAmount FROM transactioninfo;
你可以使用这个查询
SELECT concat(creditdAmount,' (Cr)') FROM
(
SELECT SUM(id) AS creditdAmount FROM transaction
)as temp;
请检查以下内容。这对你来说是值得的:
SELECT
CONCAT(CONVERT(SUM(transactioninfo.CreditAmount), char), ' (Cr)') AS creditdAmount
FROM transactioninfo