日期:2014-05-18  浏览次数:20557 次

帮我看看这条sql语句吧,就这么点分了
我是在改别人写的sql语句,这个语句主要问题是在查询时间的时候出现问题的,应该输出是全部是2007年以后的,可是为什么输出记录里还有2007年以前的,帮我看看,应该怎么改啊,
语句有点长,我搞不定了,看不懂了,希望给指点以下谢谢了,
select   top   10   *from  
(   select   distinct   tbHatchUnit.Id   as   id,tbUnit.theyear   ,tbUnit.Name,   tbZGCLocation.name   as   ZGCLocation,   tbInvestorType.name   as   investorType,   tbEconomyType.name   as   economyType,   tbHatchUnit.Type,   tbUnit.RegFund  
from   tbUnit  
join   tbHatchUnit   on   tbUnit.Id=tbHatchUnit.RefUnitId  
left   outer   join   tbIncomeInfo   on   tbIncomeInfo.RefUnitId   =tbUnit.Id  
left   outer   join   tbZGCLocation   on   tbHatchUnit.RefZGCLocationId=tbZGCLocation.Id  
left   outer   join   tbInvestorType   on   tbHatchUnit.RefInvestorTypeId=tbInvestorType.Id  
left   outer   join   tbEconomyType   on   tbUnit.RefEconTypeId=tbEconomyType.Id  
left   outer   join   tbHatchLocation   on   tbHatchLocation.RefHatchId=tbHatchUnit.Id  
where   (tbHatchUnit.Id   NOT   IN   (SELECT   tbSciencePark.refHatchId   FROM   tbSciencePark   UNION   (SELECT   tbOverseasPark.refHatchId   FROM   tbOverseasPark)))  
and   tbUnit.theYear> = '2007-1-1 '   and   tbUnit.theYear <= '2007-12-31 '  
and   tbUnit.name   like   '%北京交大科技孵化器有限公司% '  
or   tbUnit.name   like   '%北京宏翔鸿科技孵化基地有限公司% '  
group   by   tbUnit.theyear,   tbHatchUnit.Id,   tbUnit.Name,   tbZGCLocation.name,   tbInvestorType.name,tbEconomyType.name,   tbHatchUnit.Type,   tbUnit.RegFund   having   1=1
)t1
where   id   not   in  
(select   top   0   id   from  
(select   distinct   tbHatchUnit.Id   as   id,   tbUnit.Name,   tbZGCLocation.name   as   ZGCLocation,   tbInvestorType.name   as   investorType,   tbEconomyType.name   as   economyType,   tbHatchUnit.Type,   tbUnit.RegFund
from   tbUnit   join   tbHatchUnit   on   tbUnit.Id=tbHatchUnit.RefUnitId  
left   outer   join   tbIncomeInfo   on   tbIncomeInfo.RefUnitId   =tbUnit.Id  
left   outer   join   tbZGCLocation   on   tbHatchUnit.RefZGCLocationId=tbZGCLocation.Id  
left   outer   join   tbInvestorType   on   tbHatchUnit.RefInvestorTypeId=tbInvestorType.Id  
left   outer   join   tbEconomyType   on   tbUnit.RefEconTypeId=tbEconomyType.Id  
left   outer   join   tbHatchLocation   on   tbHatchLocation.RefHatchId=tbHatchUnit.Id  
where   (tbHatchUnit.Id   NOT   IN   (SELECT   tbSciencePark.refHatchId   FROM   tbSciencePark   UNION   (SELECT   tbOverseasPark.refHatchId   FROM   tbOverseasPark)))  
and   tbUnit.theYear> = '2007-1-1 '   and   tbUnit.theYear <= '2007-12-31 '  
and   tbUnit.name   like   '%北京交大科技孵化器有限公司% '  
or   tbUnit.name   like   '%北京宏翔鸿科技孵化基地有限公司% '  
group   by   tbHatchUnit.Id,   tbUnit.Name,   tbZGCLocation.name,   tbInvestorType.name,tbEconomyType.name,   tbHatchUnit.Type,   tbUnit.RegFund   ha