2个表,结构是一样的,只是用途不同。执行select (*) as total from A/B group by userid,就可以列出每个userid所拥有的条目数,我现在想将2个表的查询结果合在一起,就是只出一批查询结果,以total和userid列出,应如何查询啊?

解决方案 »

  1.   


    select (*) as total from 
    (select * from A 
     union 
    select * from B)
     as T
     group by userid
      

  2.   

    select userid,count(*) as total from 
    (select * from A 
     union 
    select * from B) K
     group by userid
      

  3.   

    select userid,count(*) as total from 
    (select * from A 
    union 
    select * from B) t 
    group by userid 
      

  4.   

    select userid,count(*) as total from 
    (select * from A 
    union all
    select * from B) K 
    group by userid 
      

  5.   

    原来是union,死活想不起来了,谢谢!