如:
select count(*) from table1  
结果为10
select count(*) from table2 
结果为20那么我想将这两个sql语句合成一个。
生成如下的结果集如何写sql?  是用union吗。好像union是行合并。有没有列合并的。
count1  count2
  10      20

解决方案 »

  1.   

    简单嘛:select (select count(*) from table1) count1,
           (select count(*) from table2) count2
       from dual;
      

  2.   

    如果我写成这样就不行了.
    select (select count(*),sum(id) from log),
           (select count(*) from log) count2
    from dual;就不行。
    因为这个会有select的值过多。但是有时需要这样,在sql的性能上有所提高一点
    如果按上面那个,要多写一个sql来做。
    有没有什么更好的办法。
      

  3.   

    select (select count(*) ||chr(32)|| sum(id) from aa) count1,(select count
    (*) || chr(32) || sum(id) from bb) count2 from dual;