how to reuse subquery result in mysql
- by chris
I'm doing a statistic job like this:
SUM |COND1 |COND2 |...
--------------------------
100 |80 | 70 |...
The SUM result is calculated from multiple tables, and the CONDs are subset of that.
I wrote a sql like this:
select tmp1.id,sum,cond1,cond2 as count from (
select id, count(*) as sum from table_1
group by table1.id) tmp1
…