SELECT sum(DISTINCT case when t1.id then t1.amount else 0 end ) as t1sumAmount
from table1 t1 left join table2 t2 on t1.id = t2.t1_id
如果t1对应多个t2,会出现t1的数量重复相加的情况,用上面的方式可去除重复
SELECT sum(DISTINCT case when t1.id then t1.amount else 0 end ) as t1sumAmount
from table1 t1 left join table2 t2 on t1.id = t2.t1_id
如果t1对应多个t2,会出现t1的数量重复相加的情况,用上面的方式可去除重复