select a.1 sum(a.2)
from a,b
where (a.1=b.1) or (a.1=b.2)
group by  a.1
我现在要让它显示a.1里面的全部内容,怎么做
我现在得到的结果是部分数据比如我要得到的结果
 部门名称    人数
…………………………
  aa          0  
…………………………
  bb         15
…………………………
  cc         20
…………………………
  dd          0 我现在得到的结果是 部门名称    人数
…………………………
  bb         15
…………………………
  cc         20
…………………………希望各位高手能出谋献策,必有重谢!!!

解决方案 »

  1.   

    select 1,sum(2) from a group by 1;
      

  2.   

    用左/右join运算符,在oracle中应是:
    ...
    where (+a.1 = b.1) or (+a.1 = b.2)
    ...
    或是
    where (a.1 =+ b.1) or (a.1 =+ b.2)
      

  3.   

    “where (+a.1 = b.1) or (+a.1 = b.2)”我试验过了,不行的
    我的sql语句写在from()里面
    select x1.1
    from(select a.1 sum(a.2)
          from a,b
          where (a.1=b.1) or (a.1=b.2)
          group by  a.1
         ) x1
    from (select a.1 sum(a.2)
          from a,b
          where (a.1=b.1) or (a.1=b.2)
          group by  a.1
         ) x2
    where x1.a1=x2.a1
      

  4.   

    如果要显示a.1里面的全部内容,直接查a表就可以了,不用联结b表了.
    select a.1 sum(a.2)
    from a
    group by  a.1
      

  5.   

    select a.1,sum(a.2)
    from a where exists (select * from b where b.1=a.1 or b.2=a.1)
    group by  a.1
      

  6.   

    select 部门名称,(select count(*) from 部门人员表 where 部门编号=部门表.部门编号) 人数 from 部门表??
      

  7.   


    补充一下,为什么在
    where     a.1(+)=a.2
      and     a.2=a.3  其中不能用AND ORACLE说在这种情况下不能有(+)运算符号出现,可不可以用其他的方式来代替。我实在想在这里有“(+)”看看各位大虾有 没有什么办法,急切等待!!!!!!!!!!
      

  8.   

    不行,
    补充一下,为什么在
    where     a.1(+)=a.2
      and     a.2=a.3  其中不能用AND ORACLE说在这种情况下不能有(+)运算符号出现,可不可以用其他的方式来代替。我实在想在这里有“(+)”看看各位大虾有 没有什么办法,急切等待!!!!!!!!!!