中国开发网: 论坛: 批评与自我批评: 贴子 503094
wynnhjg
BS一下自己不写SQL好久了.都不会写了.这么一小点分几步来写.
select t_storehouse.storehousename,
t_product.typename,
temp.sum
from t_storehouse,
t_product,
(select temp1.storehouseid,
temp1.commodityid,
sum(sum) sum
from (select storehouseid,
commodityid,
sum(count) sum
from t_commodityoperate
where t_commodityoperate.operatetype = 'in'
group by storehouseid,commodityid
union
select storehouseid,
commodityid,
-sum(count) sum
from t_commodityoperate
where t_commodityoperate.operatetype = 'out'
group by storehouseid,commodityid) temp1
group by temp1.storehouseid,temp1.commodityid) temp
where temp.storehouseid = t_storehouse.id and
temp.commodityid = t_product.typeid

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录