select count(gid) as num from (select gid from data union all select gid from data_1) a

解决方案 »

  1.   

    SELECT *
    FROM (SELECT COUNT(1) AS num,'data' AS tablename
            FROM data
            WHERE gid = '1'
            UNION ALL
            SELECT COUNT(1) AS num,'data_1' AS tablename
            FROM data_1
            WHERE gid = '1') temp
      

  2.   

    mysql的库,如果数据量比较大,效率会高么?
    还有,最有那个a是啥意思呀?
    还有别的写法么?谢谢
      

  3.   


    SQL 
    select (select count(id)   from data where gid='1') as a,(select count(id)   from data1 where gid='1') as b
    ACCESS   
    select count(id) as num, (select count(id)   from data1 where gid='1') as num1  from data where gid='1'
      

  4.   

    不好意思,看错你的意思了select sum(num1) as num1,sum(num2) as num2 from (
    select count(*) as num1,num2=0 from #data where gid=1 union all
    select num1=0,count(*) as num2 from #data_1 where gid=1) a
      

  5.   

    为啥要
    sum(num1) as num1,sum(num2) as num2   ??