请看下面这条语句,找到数据行数为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'
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'
表联接时,所得的行数并不决定于它查询什么,而是取决于查询条件.
你可以这样作测定:
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'
看它会出来多少记录.
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'