mysql - Reduce SQL statement with sum of col of result -
select *, (a / 100) a_calc, (select sum(a_calc) foo c = ? , d = ?) a_calc_sum foo c = ? , d = ? order a;
the purpose here want return rows matching original query (without sum) , have mysql calculate sum of a_calc me instead of issuing separate query. without subselect seems first row in query correct sum attached.
any ideas how reduce above query?
i think want avoid running subquery every row - here's how:
select *, / 100 a_calc, a_calc_sum foo join (select sum(a / 100) a_calc_sum foo c = ? , d = ?) x c = ? , d = ? order a;
Comments
Post a Comment