想请教大家
我要去ORACLE查4张表的总和,把和相加,在JAVA代码里可以分4次查询在相加,但这样效率低的
想问问有只需要查询一次的嘛?
用begin end 吗?还是别的什么方法
谢谢

解决方案 »

  1.   

    把四次的结果union在一起.select * from ....
    union
    select * from ....
    union
    select * from ....
    union
    select * from ....
      

  2.   

    select sum(A.n)+sum(B.n)+sum(C.n)+sum(D.n) as sum_ABCD
    from A,B,C,D
      

  3.   

    恩,谢谢
    我后来想到用UNION ALL的
    只是查询语句长的啦
    UNION ALL 和UNION 有区别吗?
      

  4.   

    我是这样的
    select sum(total) from (
    select count(*)  total from dept
    union all
    select count(*) total from emp1
    union all
    select count(*) total from emp2
    union all
    select count(*) total from emp3)
    谢谢大家
      

  5.   

    UNION 消除重复记录,UNION ALL不消除
    UNION ALL效率要高