G
ganh
Unregistered / Unconfirmed
GUEST, unregistred user!
很急很急很急很急很急!!!!!!!
我的数据库是SQL SERVER 7。0
我有四张表,分别是 seller(客户代码表) ,seller_type(客户类型表),
stock (客户库存表),sell_daily (销售动态表)
表结构如下
seller /*客户代码表*/ seller_type/*客户类型代码*/
-------------------------- ---------------------------------
seller_type /*客户类型*/ type_code /*类型代码*/
seller_code /*客户代码*/ type_name /*类型名称*/
seller_name /*客户名称*/
stock /*现今库存表*/ sell_daily /*销售动态表*/
--------------------------------- -------------------------------------
seller_code /*客户代码*/ seller_code /*客户代码*/
goods_name /*货物名称*/ goods_name /*货物名称*/
stock /*现今库存量*/ last_stock /*上次剩余库存*/
bad /*库存损坏量*/ now_stock /*现在的库存*/
input /*进货量*/
sell /*销售量*/
bad /*损坏量*/
sell_date /*日期*/
我现在要求查询出每个客户的 进货量,销售量,损坏量,库存数,并作小计
我的sql语句如下
select sell_daily.seller_code as 经销商代码,seller_type.type_name as 经销商类型,
seller.seller_name as 经销商名称,sell_daily.goods_name as 货物名,
sum(input) as 进货量,sum(sell) as 销售量,
sum(sell_daily.bad)as 损坏量,stock.stock as 现库存量
from sell_daily,seller,seller_type,stock
where sell_daily.seller_code=seller.seller_code
and seller.seller_type=seller_type.type_code
and stock.seller_code=sell_daily.seller_code
and stock.goods_name=sell_daily.goods_name
group by sell_daily.seller_code,seller_type.type_name,seller.seller_name,
sell_daily.goods_name,stock.stock
union
select sell_daily.seller_code as 经销商代码,seller_type.type_name as 经销商类型,
seller.seller_name as 经销商名称,'小计' as 货物名,sum(input) as 进货量,
sum(sell_daily.sell) as 销售量,sum(sell_daily.bad)as 损坏量,
sum(stock.stock) as 现库存量
from sell_daily,seller,seller_type,stock
where sell_daily.seller_code=seller.seller_code
and seller.seller_type=seller_type.type_code
and stock.seller_code=sell_daily.seller_code
and stock.goods_name=sell_daily.goods_name
group by sell_daily.seller_code,sell_daily.seller_code,
seller_type.type_name,seller.seller_name
order by sell_daily.seller_code,seller.seller_name
查询出来却发现 结果不知为什么都乘了一定的倍数 请教各位高手这是怎么回事?如何解决?
是不是我的连接有问题
我的数据库是SQL SERVER 7。0
我有四张表,分别是 seller(客户代码表) ,seller_type(客户类型表),
stock (客户库存表),sell_daily (销售动态表)
表结构如下
seller /*客户代码表*/ seller_type/*客户类型代码*/
-------------------------- ---------------------------------
seller_type /*客户类型*/ type_code /*类型代码*/
seller_code /*客户代码*/ type_name /*类型名称*/
seller_name /*客户名称*/
stock /*现今库存表*/ sell_daily /*销售动态表*/
--------------------------------- -------------------------------------
seller_code /*客户代码*/ seller_code /*客户代码*/
goods_name /*货物名称*/ goods_name /*货物名称*/
stock /*现今库存量*/ last_stock /*上次剩余库存*/
bad /*库存损坏量*/ now_stock /*现在的库存*/
input /*进货量*/
sell /*销售量*/
bad /*损坏量*/
sell_date /*日期*/
我现在要求查询出每个客户的 进货量,销售量,损坏量,库存数,并作小计
我的sql语句如下
select sell_daily.seller_code as 经销商代码,seller_type.type_name as 经销商类型,
seller.seller_name as 经销商名称,sell_daily.goods_name as 货物名,
sum(input) as 进货量,sum(sell) as 销售量,
sum(sell_daily.bad)as 损坏量,stock.stock as 现库存量
from sell_daily,seller,seller_type,stock
where sell_daily.seller_code=seller.seller_code
and seller.seller_type=seller_type.type_code
and stock.seller_code=sell_daily.seller_code
and stock.goods_name=sell_daily.goods_name
group by sell_daily.seller_code,seller_type.type_name,seller.seller_name,
sell_daily.goods_name,stock.stock
union
select sell_daily.seller_code as 经销商代码,seller_type.type_name as 经销商类型,
seller.seller_name as 经销商名称,'小计' as 货物名,sum(input) as 进货量,
sum(sell_daily.sell) as 销售量,sum(sell_daily.bad)as 损坏量,
sum(stock.stock) as 现库存量
from sell_daily,seller,seller_type,stock
where sell_daily.seller_code=seller.seller_code
and seller.seller_type=seller_type.type_code
and stock.seller_code=sell_daily.seller_code
and stock.goods_name=sell_daily.goods_name
group by sell_daily.seller_code,sell_daily.seller_code,
seller_type.type_name,seller.seller_name
order by sell_daily.seller_code,seller.seller_name
查询出来却发现 结果不知为什么都乘了一定的倍数 请教各位高手这是怎么回事?如何解决?
是不是我的连接有问题