仓库的 进/出 存储数量问题。
我现在希望得到每个仓库中有多少库存并且要这个仓库的详细的信息
也就是需要以下字段
house_id,house_name,stored,memo其中stored是通过以下的sql语句计算出来的
--计算当前各个仓库中的库存总量
select house,sum(quantity) as 'stored' 
from store
group by house 我怎样才能select得到想要的这个结果
表结构如下create table warehouse
(
 house_id tinyint primary key,
 house_name varchar(10) not null,
 memo varchar(100)default null
)create table store
(
 recno int identity(0,1) primary key,
 house tinyint foreign key references warehouse(house_id),
 quantity smallint not null,
 memo varchar(100) default null,
)

解决方案 »

  1.   

    select w.house_name,sum(s.quantity) as 'stored',w.memo
    from store s left join warehouse w on s.house=w.houser_id
    group by w.house_name,w.memo
      

  2.   

    我是这样写:
    select a.house_id,a.house_name,b.cc
    from warehouse a ,(select sum(quantity) as cc ,house from store group by house) b 
    where a.house_id=b.house
    我测试过,跟楼上的大哥的结果是一样的,但是我想问一下大家,那个效率高呢???
      

  3.   

    有left...还有group by 这样会比较慢
      

  4.   

    http://www.quandi.cn/WebForm1.aspx?quandi_id=lxzm1001
    圈地网