left join - Mysql query that includes TWO sums from columns in other tables -
got query running 1 sum different table, works (and obtained forum well):
select r.rep_id repid, r.rep_desbrev repdesc, ifnull(sum(rd.repdata_cant), 0) cant repuestos r left join rep_data rd, on rd.repdata_repid = r.rep_id group rd.repdata_repid
now, thing i'd add column obtains total inventory (something
ifnull(sum(i.inv_cant), 0) inv) table inventario i.inv_repid = r.rep_id
this value can obtained means of join, in exact same way got first statement works, have not found way include both sums in 1 query.
any ideas? thanks!
try query example
select t1.id, ifnull(sum(t1.my_column),0) sum1, ifnull(other.sum,0) sum2 table t1 left join (select id , sum(other_table_column) other_table group id) other on t1.id = other.id group t1.id
Comments
Post a Comment