使用 mySQL 在 GROUP_CONCAT 之后求和数据

2022-01-09 00:00:00 sum mysql

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

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

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

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

请问如何使用 ApplicableTaxesRate 数据 (5.000,5.000,23.000,23.000) 对这些数据求和?

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

所以我应该得到 56.00.

谢谢.

推荐答案

试试这个:

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

相关文章