SQL SERVER的怪问题,你能解决吗
vt 2003-10-09 10:05:00 请看下面的两个SQL
1)
select sum(b.销售额) as total from
(
select a.货号,sum(a.数量) as 销售数量,sum(a.售价 * a.数量) as 销售额 from
(
select 货号,售价, 数量 from sale_detail where
时间 between cast('2003-10-7 00:00:00' as smalldatetime)
and cast('2003-10-7 23:00:00' as smalldatetime)
union all
select 货号,售价, 数量 from old_sale_detail where
时间 between cast('2003-10-7 00:00:00' as smalldatetime)
and cast('2003-10-7 23:00:00' as smalldatetime)
) a group by a.货号
) b
2)
select sum(b.销售额) as total from
(
select a.货号,sum(a.数量) as 销售数量,sum(a.售价 * a.数量) as 销售额 from
(
select 货号,售价, sum(数量) as 数量 from sale_detail where 货号 in (select product.货号 from product inner join provider on product.供应商编号=provider.供应商编号 where product.货号 like '%') and
时间 between cast('2003-10-7 00:00:00' as smalldatetime)
and cast('2003-10-7 23:00:00' as smalldatetime) group by 货号,售价
union all
select 货号,售价, sum(数量) as 数量 from old_sale_detail where 货号 in (select product.货号 from product inner join provider on product.供应商编号=provider.供应商编号 where product.货号 like '%') and
时间 between cast('2003-10-7 00:00:00' as smalldatetime)
and cast('2003-10-7 23:00:00' as smalldatetime) group by 货号,售价
) a group by a.货号
) b
可以保证sale_detail 和 old_sale_detail 里面的货号全都在product中,但两个查询的结果是不一样的,很奇怪的,
不知是什么原因,你能看出问题吗
我把这个数据库(test)里的表备份下来了,要的话,把EMAIL留下,你可以自己试试看,
我一直在线等待结果