使用mySQL的GROUP_CONCAT之后的SUM数据

时间:2018-03-09 15:00:51

标签: mysql sum

我正在使用phpMyAdmn,我在mySQL中有这个查询:

SELECT BIL_Date, BIL_Rate, BIL_Quantity,
GROUP_CONCAT(COALESCE(STX_Amount, "0")) AS ApplicableTaxesRate
FROM ___BillableDatas
LEFT JOIN ___SalesTaxes
  ON FIND_IN_SET(STX_Id, BIL_ApplicableTaxes) > 0
WHERE BIL_HotelId='cus_CNHLMiMOzP5cuM'
  AND BIL_BookingId='2'
ORDER BY BIL_Date
ASC

这里是表结构的SQL小提琴: http://sqlfiddle.com/#!9/49ee80/8

如何使用ApplicableTaxesRate数据(5.000,5.000,23.000,23.000)来计算这些数据的总和?

所以我应该56.00

感谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

SELECT BIL_Date, BIL_Rate, BIL_Quantity,
GROUP_CONCAT(COALESCE(STX_Amount, "0")) AS ApplicableTaxesRate,SUM(STX_Amount)as sum
FROM ___BillableDatas
LEFT JOIN ___SalesTaxes
ON FIND_IN_SET(STX_Id, BIL_ApplicableTaxes) > 0
WHERE BIL_HotelId='cus_CNHLMiMOzP5cuM'
AND BIL_BookingId='2'
ORDER BY BIL_Date
ASC