0

ここに私のクエリの一部があります

(SUM(dr.drv)/100)*
  (st.suppliers1_value+st.suppliers2_value+st.suppliers3_value+st.suppliers4_value)

これにより、複数の行が生成されます。それらすべてのSUMを取得したい。私は試した

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
4

1 に答える 1

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
于 2013-08-05T12:13:38.453 に答える