第一条:
where a.userid in ('2', '3', '64') 有三条记录
where a.userid in ('2', '3', '64') and a.userid = b.xmjlbh(+) 有三条记录,但和表sl_hc_xqd相关的信息是null,
最后加上条件b.djztid in ('02', '03'),当然什么记录都没有了。
--------------------------
第二条:就不同了,虽然作了左连接后和表sl_hc_xqd相关的信息是null,
但加上条件a.userid in ('2', '3', '64')当然是返回三条记录啦。

解决方案 »

  1.   

    把你想要的东西好好理清楚。
    不要先写select ...
    而应先写from ... where ...
      

  2.   

    刚从sql server转向oracle,好多东西还不懂.我记得这样写在sql server中是可以的啊按你刚才的解释,我改变了一下条件的顺序,可执行结果还是一样的啊
    select a.userid, a.username, count(b.djid) as xqd
    from userinfo a, sl_hc_xqd b
    where b.djztid in ('02', '03')
    and a.userid = b.xmjlbh(+)
    and a.userid in ('2', '3', '64')
    group by a.userid, a.username
      

  3.   

    试试这个:
    select a.userid,a.username,count(b.djid) xqd from
    (select userid,username 
     from userinfo where a.userid in ('2', '3', '64') group by userid,username) a
    (select * from sl_hc_xqd  where djztid in ('02', '03')) b
    where a.userid = b.xmjlbh(+)
      

  4.   

    已经给分了,不知道什么时候能收到,kkkk
    难道不能马上给分吗?