SQL减法

skysmmg 2008-10-17 04:39:27
select distinct a.fGoods_name AS 物品名, b.fnum - c.fOrder_amount AS 库存 from t_goods a,t_stockin_detail b,t_saleout_detail c
where a.fGoods_id=b.fGoods_id and b.fGoods_id=c.fGoods_id and a.fGoods_id=c.fGoods_id order by fGoods_name
这样查出来的语句中fGoods_name存在没合并情况,求助怎么解决
例如
{DM版}L6 2
{DM版}L6 1
{DM版}L6 -2
{DM版}L6 3
01 6
01 -1
01 1
01 3

怎么让他查处的如下
{DM版}L6 4
01 9
...全文
470 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
jimoshatan 2008-10-17
  • 打赏
  • 举报
回复
SELECT S_NAME,SUM(QTY)QTY
FROM A
GROUP BY S_NAME
skysmmg 2008-10-17
  • 打赏
  • 举报
回复
谢谢!!!你直接点出了我的错误!
dlpseeyou 2008-10-17
  • 打赏
  • 举报
回复
select a.fGoods_name AS 物品名,sum( b.fnum - c.fOrder_amount) AS 库存 from t_goods a,t_stockin_detail b,t_saleout_detail c
where a.fGoods_id=b.fGoods_id and b.fGoods_id=c.fGoods_id and a.fGoods_id=c.fGoods_id
group by a.fGoods_name order by fGoods_name
Liyingyue_FFS 2008-10-17
  • 打赏
  • 举报
回复
select  a.fGoods_name AS 物品名, sum(b.fnum - c.fOrder_amount) AS 库存 from t_goods a,t_stockin_detail b,t_saleout_detail c 
where a.fGoods_id=b.fGoods_id and b.fGoods_id=c.fGoods_id and a.fGoods_id=c.fGoods_id order by fGoods_name
group by a.fGoods_name


用这个试一下
csdyyr 2008-10-17
  • 打赏
  • 举报
回复

select a.fGoods_name AS 物品名, sum(b.fnum - c.fOrder_amount) AS 库存
from t_goods a,t_stockin_detail b,t_saleout_detail c
where a.fGoods_id=b.fGoods_id and b.fGoods_id=c.fGoods_id and a.fGoods_id=c.fGoods_id
group by fGoods_name
子陌红尘 2008-10-17
  • 打赏
  • 举报
回复
sum()+group by

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧