select 货品编号,余额 =sum(case 收发标志 when '收' then 数量 else -数量 end ) from tb group by 货品编号
SELECT (select sum(数量) from 业务发生表子表 where 收发标志='收')-(select sum(数量) from 业务发生表子表 where 收发标志='发') AS 余额 FROM 业务发生表子表 GROUP BY 业务发生表子表.货品编号 ORDER BY 业务发生表子表.货品编号; 查不出数据呀
如果用一楼的:SELECT (select sum(数量) from 业务发生表子表 where 收发标志='收' and 货品编号=a.货品编号 )-(select sum(数量) from 业务发生表子表 where 收发标志='发' and 货品编号=a.货品编号) AS 余额 FROM 业务发生表子表 a GROUP BY 业务发生表子表.货品编号 ORDER BY 业务发生表子表.货品编号
select 货品编号,余额 =sum(case 收发标志 when '收' then 数量 else -数量 end ) from tb group by 货品编号 -------------------------------------------------------------------- 这个不行吗?
select 货品编号,余额 =sum(case 收发标志 when '收' then 数量 else -数量 end ) from 业务发生子表 group by 货品编号
select 货品编号,余额 =sum(case 收发标志 when '收' then 数量 else -数量 end ) from 业务发生子表 group by 货品编号 ------------------------------------------ 在sql服务器中可以得到 但在mdb中不行
from tb
group by 货品编号
FROM 业务发生表子表
GROUP BY 业务发生表子表.货品编号
ORDER BY 业务发生表子表.货品编号;
查不出数据呀
FROM 业务发生表子表 a
GROUP BY 业务发生表子表.货品编号
ORDER BY 业务发生表子表.货品编号
from tb
group by 货品编号
--------------------------------------------------------------------
这个不行吗?
from 业务发生子表
group by 货品编号
select 货品编号,余额 =sum(case 收发标志 when '收' then 数量 else -数量 end )
from 业务发生子表
group by 货品编号
------------------------------------------
在sql服务器中可以得到
但在mdb中不行