请,我的请求是从项目表和每日交易表创建月度报表表
答案 0 :(得分:0)
试试这个:
select i.id,i.code.i.item_name ,
sum(if(m.action='purchased',m.quantity,0)) as total_purchased,
sum(if(m.action='sold',m.quantity,0))*-1 as total_sold,
sum(if(m.action='purchased',m.quantity,0))+sum(if(m.action='sold',m.quantity,0)) as balance
from items i
inner join movements m on i.code=m.code
group by i.code;