这是我查询的一部分
(SUM(dr.drv)/100)*
(st.suppliers1_value+st.suppliers2_value+st.suppliers3_value+st.suppliers4_value)
这将生成多行。我想获得所有这些的总和。我试过了
SUM(SUM(dr.drv)/100)*
(st.suppliers1_value+st.suppliers2_value+st.suppliers3_value+st.suppliers4_value)
as total drv_amount
但这引发了错误。有人可以指引我正确的方向吗?
这是整个查询:
SELECT SUM(dr.tickets_sold) as tickets_total_amount,
SUM(dr.drv) as drv_total_amount,
FORMAT(((SUM(dr.drv)/100) * (st.suppliers1_value+st.suppliers2_value+st.suppliers3_value+st.suppliers4_value) ),2 ) as supplier_commission,
FORMAT(((SUM(dr.drv)/100) * st.exhibitor_value),2) as exhibitor_commission,
FORMAT(((SUM(dr.drv)/100) * st.circuit_value),2) as distributer_commission,
FORMAT(((SUM(dr.drv)/100) * (st.suppliers1_value+st.suppliers2_value+st.suppliers3_value+st.suppliers4_value)+((SUM(dr.drv)/100) * st.circuit_value )),2) as film_hire_total
FROM com_pro_dr as dr
INNER JOIN com_pro_ratecard_rates AS rt
ON (dr.movie_id=rt.movie_id and
dr.theater_id=rt.theater_id and
dr.showtime_id=rt.showtime_id and
dr.category_id=rt.category_id and
dr.applied_date = rt.date_apply)
INNER JOIN com_pro_ratecard as rc ON (rc.id=rt.ratecard_id)
INNER JOIN com_pro_movie as m ON (m.id=dr.movie_id)
INNER JOIN com_pro_theater as t ON (t.id=dr.theater_id)
INNER JOIN com_pro_share as st ON (st.id=rc.share_id)
INNER JOIN com_pro_theater_dr as td ON (td.theater_id=dr.theater_id)
INNER JOIN com_pro_circuit as c ON (c.id =td.circuit_id)
WHERE 1
最佳答案
您可以随时执行以下操作:
SELECT SUM(val)
FROM
(
SELECT (SUM(dr.drv)/100)*
(st.suppliers1_value+st.suppliers2_value+st.suppliers3_value+st.suppliers4_value)
AS val
/* the rest of your current query */
) AS a
关于mysql - 数学运算后获取mysql SUM,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18057617/