第一条sql:select count(1) from measurereport A where MEAS_VALID = 0 
第二条sql:select count(1) from measurereport A left join ABIS_HOCMP B on(A.Callid = B.Callid
                and A.Lac = B.Lac and A.ci = B.CI) where MEAS_VALID = 0 
为什么第二条sql查询出的数据会比第一条sql的数据多,左联接不是查询出左边的所有表和关联条件一致的吗,两条sql查询出的数据条数应该一样多

解决方案 »

  1.   

    -- 说明连接条件不唯一对应:ABIS_HOCMP 表中的 Callid 可能有(重复) N条记录 对应 measurereport 表中的记录!
      

  2.   

    -- 说明连接条件不唯一对应:
    -- ABIS_HOCMP 表中的 Callid 可能有(重复) N条记录 对应 measurereport 表中的某条记录!
      

  3.   


    select Callid ,Lac ,ci,count(1)
    from measurereport 
    group by Callid ,Lac ,ci
    having count(1)>1select Callid ,Lac ,ci,count(1)
    from ABIS_HOCMP
    group by Callid ,Lac ,ci
    having count(1)>1这2个查询里面有数据的话 你左连接肯定会多的
      

  4.   

    select count(distinct A.Callid ,A.Lac ,A.ci ) from measurereport A left join ABIS_HOCMP B on(A.Callid = B.Callid
      and A.Lac = B.Lac and A.ci = B.CI) where MEAS_VALID = 0