求助:两个SQL查询的结果的和怎么会不相同,大虾们帮我看看?在线急等
下面这两个Sql语句,当查询条件相同时,(1)中的Ajc这列的和应该和
(2)中的A这列的和相等,可是我用下面的条件测试却不相同。
如果把两个日期都设为同一天,那么结果就会相同,找了1天,没找到原因。
--(1)废品率图表
declare @dtB datetime
declare @dtE datetime
declare @faculty varchar(4)
set @dtB= '2007-1-4 '
set @dtE= '2007-1-6 '
set @faculty= '一科 '
select convert(char(10),G.produceDate,120) dt,sum(w) w,
sum(case when ASx is not NULL
then ASx else AXj end) as Ajc,
sum(Asx) Asx,sum(Axj) Axj
from
(select ProductNo,ProduceDate,sum(WasterQtyT) w,
sum(case wpno when '114 ' then ActualQty+WasterQtyT end) ASx,
sum(case wpno when '103 ' then ActualQty+WasterQtyT end) AXj
from gwkBaseData
where ProduceDate> =@dtB
and ProduceDate <=@dtE
and Faculty=@Faculty
group by ProductNo,ProduceDate) G group by ProduceDate
--(2)废品率报告
declare @dtB datetime
declare @dtE datetime
declare @faculty varchar(4)
set @dtB= '2007-1-4 '
set @dtE= '2007-1-6 '
set @faculty= '二科 '
select G.ProductNo,G.W,
case when ASx is not NULL then ASx else AXj end as A
from
(select ProductNo,sum(WasterQtyT) w,
sum(case WPNo when '114 ' then ActualQty+WasterQtyT end) ASx,
sum(case WPNo when '103 ' then ActualQty+WasterQtyT end) AXj
from gwkBaseData
where ProduceDate> =@dtB
and ProduceDate <=@dtE
and Faculty=@Faculty
group by ProductNo) G left join ProductInfo P
on G.ProductNo=P.ProductNo
where (isnull(ASx,0)+isnull(W,0)+isnull(AXj,0))> 0
------解决方案--------------------看不到表数据,不好处理呀
------解决方案--------------------看到这样密密麻麻的,只有忽悠一贴!
UP