表A 的 id 总行数
表B 的 id 总行数
表C 的 id 总行数
表D 的 id 总行数然后相加的值select count(A.id)+count(B.id)+count(C.id)+count(D.id) from A,B,C,D  ?????? 此式错误。

解决方案 »

  1.   

    select sum(行数) from 
    (select count(id) as 行数 from a
    union  all
    select count(id) as 行数 from b
    union  all
    select count(id) as 行数 from c
    union  all
    select count(id) as 行数 from d
    )
      

  2.   

    select
      count(1)
    from
     (select count(id) as num  from a
      union all
      select count(id) as num from b
      union all
      select count(id) as num from c
      union all
      select count(id) as num from d
    )t
      

  3.   

    select
    (select count(ID) from A)+(select count(ID) from B)+(select count(ID) from C)+(select count(ID) from D)
      

  4.   

    select sum(num) from(
    select count(1) as num from A
    union all count(1) from b
    union all count(1) from c
    union all count(1) from d) a
      

  5.   

    select count(A.id)+count(B.id)+count(C.id)+count(D.id) from A,B,C,D ?????? 此式错误。
    select (select count(*) from a)+(select count(*) from b)+select (select count(*) from c)+(select count(*) from d)
      

  6.   

    select 1 from a
    union  all
    select 1 from b
    union  all
    select 1 from c
    union  all
    select 1 from d
    select @@rowcount
      

  7.   

    select sum(行数) from 
    (select count(id) as 行数 from a
    union  all
    select count(id) as 行数 from b
    union  all
    select count(id) as 行数 from c
    union  all
    select count(id) as 行数 from d
    ) tt
      

  8.   

    這個也不對啊
    下面就產生4條記錄
    sum才對
      

  9.   

    SELECT SUM(行数) AS Expr1
    FROM (SELECT COUNT(id) AS 行数
            FROM A
            UNION ALL
            SELECT COUNT(id) AS 行数
            FROM B
            UNION ALL
            SELECT COUNT(id) AS 行数
            FROM C
            UNION ALL
            SELECT COUNT(id) AS 行数
            FROM D) tt
    只有这个是成功的。无语。。