select goods_id as 商品号,number as 库存,(select sum(数量) from sale where sale.goods_id =stock.goods_id  and sale.sale_time='2004-11-03') as 销售数量 from stock order by goods_id不知行不,仅供参考吧.

解决方案 »

  1.   

    上面,估计不行!销售数量是不是在 销售明细表 sale 中
      

  2.   

    方法有二一是分组; 二是用Union
      

  3.   

    前一天的销售数量?
    怎么知道?你在数据表里记录了吗?销售明细表sale应该有数量字段吧?
      

  4.   

    感觉在两个表上写SQL语句不太合理,虽然可以实现。
    建议这样,做一个事务处理:
    表sale每增加一行,就在表stock的相应商品的数量(number)上减1(或减卖出的数量),这样再查询的时候写SQL语句也比较简单清楚。
      

  5.   

    记录的条数就是销售数量select goods_id as 商品号,number as 库存,(select count(goods_id) from sale where sale.goods_id =stock.goods_id  and sale.sale_time='2004-11-03') as 销售数量 from stock order by goods_id
      

  6.   

    select stock.Goods_id, stock.number-subsale.SubNum As Num from stock inner join
    (select count(Goods_id) As SubNum,Goods_id from sale 
    where DateDiff(day,sale_time,getdate())=1
    group by Goods_id) subsale
    on stock.Goods_id = subsale.Goods_id楼主,你试一下吧,应该可以的。
      

  7.   

    对表sale查看前一天每个商品的销售数量可以这样:
    select Goods_id,count(*) from sale
    where  sale_time='2004-11-3'
    group by Goods_id
      

  8.   

    sale 表里竟然没有记录销售的数量,呵呵,我也帮不了你
      

  9.   

    库存里的数量:
    Select id,(select count(*) From sale Where Goods_id=S.Goods_id) as Remain From stock S
      

  10.   

    (上面的错了)
    库存里的数量:
    Select id,number-(select count(*) From sale Where Goods_id=S.Goods_id) as Remain From stock S
      

  11.   

    其实我觉得!在楼主的程序里,应该有每出售一件商品,都会在库存里减去1这个功能!(很基本的)
    所以商品的库存数量应该是stock里的数量。