SUM datas after a GROUP_CONCAT with mySQL

2019-02-28 03:09发布

问题:

I'm using phpMyAdmn and I've this query in 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

Here a SQL Fiddle for tables structure: http://sqlfiddle.com/#!9/49ee80/8

How can I use the ApplicableTaxesRate datas (5.000,5.000,23.000,23.000) to make a sum of these datas please ?

So I should get 56.00.

Thanks.

回答1:

Try this :

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


标签: mysql sum