有2张表,结构一样
select sum(count(*)) from (select count(*) from details20091201 union all select count(*) from details20091202)
想把2个表算出来的结果求和,但是一直报错应该怎么改?

解决方案 »

  1.   

    select 
    (select count(*) from details20091201)
    +(select count(*) from details20091202)
      

  2.   

    select sum(cnt) from 
    (
    select count(*) cnt from details20091201 
    union all 
    select count(*) cnt from details20091202
    ) t
      

  3.   

    select sum(count(*)) from (select count(*) from details20091201 union all select count(*) from details20091202) cc
    try it
      

  4.   

    select sum(cnt) from 
    (
    select 1 cnt from details20091201 
    union all 
    select 1 cnt from details20091202
    ) t
      

  5.   

    select count(*)
    from(
    select * from details20091201 
    union all
    select * from details20091202 
    )a
      

  6.   

    union 里没有列名是不行的select sum(count(*)) from (
    select count(*) cc from details20091201 union all 
    select count(*) from details20091202)
      

  7.   

    select sum(cc) from (
    select count(*) cc from details20091201 union all 
    select count(*) from details20091202)
    or
    select count(*)
    from(
    select * from details20091201  
    union all
    select * from details20091202  
    )a
      

  8.   

    能解释一下2L的
    select 
    (select count(*) from details20091201)
    +(select count(*) from details20091202)里面"+"是不是相当于union?
    如果我需要对两个字段求和还可以用这种形式吗?
    比如
    select sum(cnt),sum(cnt1) from 
    (
    select count(*) cnt ,sum(ye) cnt1 from details20091201 
    union all 
    select count(*) cnt,sum(ye) cnt1 from details20091202
    ) t
    还可以改成2L那种形式吗?
      

  9.   

    能解释一下2L的
    select  
    (select count(*) from details20091201)
    +(select count(*) from details20091202)里面"+"是不是相当于union?
    --不是加在那里是算术计算,而UNION 是结果集的合并。
      

  10.   

    select sum(cnt),sum(cnt1) from  
    (
    select count(*) cnt ,sum(ye) cnt1 from details20091201  
    union all  
    select count(*) cnt,sum(ye) cnt1 from details20091202
    ) t
    还可以改成2L那种形式吗?--这样是可以的。
      

  11.   


    说实话,根本没看懂你这个需求的意思.最好给出完整的表结构,测试数据,计算方法和正确结果.发帖注意事项
    http://topic.csdn.net/u/20091130/21/fb718680-98ff-4afb-98d8-cff2f8293ed5.html?24281
      

  12.   

    那要这样,土炮:
    select 
        (select count(*) from details20091201)
        +(select count(*) from details20091202) cnt,
        (select sum(ye) from details20091201)
        +(select sum(ye) from details20091202) amt