仓库的 进/出 存储数量问题。
我现在希望得到每个仓库中有多少库存并且要这个仓库的详细的信息
也就是需要以下字段
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,
)
我现在希望得到每个仓库中有多少库存并且要这个仓库的详细的信息
也就是需要以下字段
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,
)
from store s left join warehouse w on s.house=w.houser_id
group by w.house_name,w.memo
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
我测试过,跟楼上的大哥的结果是一样的,但是我想问一下大家,那个效率高呢???
圈地网