SQL-对比两表中数据

需求:表1中有多行id相同

select a.item_code, totalAmount , b.online_qty
from (select item_code, sum(a.online_qty) as TotalAmount
      from serial_bal a
      where a.wh_code = 'SJ38'
      group by item_code
     ) a left join
     (select item_code,online_qty
      from wh_bal b
      where b.whcode = 'SJ38'
     ) b
     on a.item_code = b.item_code
	 where TotalAmount != b.online_qty

你可能感兴趣的:(mysql,数据库)