请看下面这条语句,找到数据行数为2w多条,如果goodscount 改成t.*就能找到12w条,请问这是什么问题,而且找到12w条才是正确的
select '2' as g,goodscount from sale s  inner join saledetail t on s.saleid=t.saleid  inner join dept d on s.stationcode=d.stationid  inner join groupset g on d.groupid=g.groupid  where   transdate>'2010-6-21 00:00:00' and transdate<='2011-6-21 23:59:59' 

解决方案 »

  1.   

    goodscount是saledetail 里面的
      

  2.   

    不对吧.
    表联接时,所得的行数并不决定于它查询什么,而是取决于查询条件.
    你可以这样作测定:
    select 1 from sale s inner join saledetail t on s.saleid=t.saleid   
    inner join dept d on s.stationcode=d.stationid inner join groupset g on d.groupid=g.groupid   
    where transdate>'2010-6-21 00:00:00' and transdate<='2011-6-21 23:59:59' 
    看它会出来多少记录.
      

  3.   

    从查询语句的角度讲,把上面 select 子句里的 1 换成任何关联表中的任何行,所得的总行数不变.
      

  4.   

    3楼的查出来也是2w多条,不对。像下面这种就能找到12w多条,还有,t(saledetail )表里面除了goodscount外,其他的字段都能找出12w条,比如select t.saleid...也可以!select t.* from sale s inner join saledetail t on s.saleid=t.saleid   
    inner join dept d on s.stationcode=d.stationid inner join groupset g on d.groupid=g.groupid   
    where transdate>'2010-6-21 00:00:00' and transdate<='2011-6-21 23:59:59' 
      

  5.   

    你的完整语句就是这个吗?是否还有group by把重复的记录去掉了
      

  6.   

    就这个,不过我发现问题了,原来goodscount添加了索引,但是具体不知道为什么,我把goodscount的索引去掉之后就好了。这是什么原因