这个问题解决过。思想是将这个查询分成三个查询。第一个只查编号。第二个查数量(出)
第三个查数量入。然后再将这三个连接起来。因为我现在网吧上网,给两个大概的模型给你,
你在查询工具中试试看好吗(我没办法调试)。
(1):
select a.编号,b.数量(出), c.数量(入) from
(select distinct a.编号 as 编号 from table) a,
(select 编号 as 编号1,sum(数量(出)) as 数量(出)from table where 出/入=c group by 编号) b,
(select 编号 as 编号2,sum(数量(入)) as 数量(入)from table where 出/入=l group by 编号) c
left join b on a.编号=b.编号1
left join c on a.编号=c.编号2
(2):
select a.编号,b.数量(出), c.数量(入) from
(select distinct a.编号 as 编号 from table) a left join
(select 编号 as 编号1,sum(数量(出)) as 数量(出)from table group by 编号) b,
on a.编号=b.编号1
left join
(select 编号 as 编号2,sum(数量(入)) as 数量(入)from table group by 编号) c
on a.编号=c.编号2