select spbm from a where spbm=1 union
select spbm from b where spbm=1 union
select spbm from c where spbm=1 union
select spbm from d where spbm=1 union
select spbm from e where spbm=1 union
select spbm from f where spbm=1 union
select spbm from g where spbm=1

解决方案 »

  1.   

    select sum(cont) as cont 
    from(
    select count(*) as cont from a where spbm=1 union
    select count(*) as cont from b where spbm=1 union
    select count(*) as cont from c where spbm=1 union
    select count(*) as cont from d where spbm=1 union
    select count(*) as cont from e where spbm=1 union
    select count(*) as cont from f where spbm=1 union
    select count(*) as cont from g where spbm=1
    ) ta
      

  2.   


    同意楼上说得.
    select count(*) from
    (
    select * from a where spbm=1 union
    select * from b where spbm=1 union
    select * from c where spbm=1 union
    select * from d where spbm=1 union
    select * from e where spbm=1 union
    select * from f where spbm=1 union
    select * from g where spbm=1
    )table
      

  3.   

    select count(*) from
    (
    select * from a where spbm=1 union
    select * from b where spbm=1 union
    select * from c where spbm=1 union
    select * from d where spbm=1 union
    select * from e where spbm=1 union
    select * from f where spbm=1 union
    select * from g where spbm=1
    )table对的
      

  4.   

    if exists( select * from (
    select spbm from a where spbm=1 union all
    select spbm from b where spbm=1 union all
    select spbm from c where spbm=1 union all
    select spbm from d where spbm=1 union all
    select spbm from e where spbm=1 union all
    select spbm from f where spbm=1 union all
    select spbm from g where spbm=1) a)
    begin
      print '有呀'
    end else  print '不好意思,沒有'哈哈,上面的可以吧
      

  5.   


    if exists(select * 
    from(
    select aa=1 from a where spbm=1
    union 
    select aa=1 from b where spbm=1
    union
    select aa=1 from c where spbm=1
    union
    select aa=1 from d where spbm=1
    union
    select aa=1 from e where spbm=1
    union
    select aa=1 from f where spbm=1
    union
    select aa=1 from b where spbm=1
    )a)
    print '有'
    else
    print '无'
      

  6.   

    都不错,关键是union的应用,另外,由于只关心spbm这个字段,所以有些select * 来union的可能会比较费资源吧~所以只需select spbm来union就可以了。那个select count(spbm) as cont的方法也很不错~~结贴。