解决方案 »

  1.   

    另外如果table1,2,3,4如果数据量大,建议在这几个表对应的id列加索引
      

  2.   


    -- 把子查询做成一个 function 比较方便。
    -- PS : TSQL 是 SQL Server 。
    select SUM(rn) from (
    select COUNT(*) as rn from t1 where id = 100 
    union all
    select COUNT(*) from t2 where id = 100 
    union all
    select COUNT(*) from t3 where id = 100 
    union all
    select COUNT(*) from t4 where id = 100  
    )