表A:
name   age  date
张三   11   1988
李四   11   1988
王五   11   1988表B
name   age  date
张三   11   1988
李四   11   1988
赵六  11   1988如上:有多张结构相同的表,现在我要从这几张表中统计出学生人数,如果是一种表的话可以 select count(distinct(name)) from tablename.
如果多张表的时候sql语句该怎么写呢??????????????????(多张表的结构完全相同)

解决方案 »

  1.   

    select count(1) from (select * from A union select * from B) T
      

  2.   

    select count(distinct(name)) from (
    select name from a
    union all
    select name from b
    ...
    union all
    select name from n) aorselect count(name) from (
    select name from a
    union 
    select name from b
    ...
    union 
    select name from n) a
      

  3.   

    select count(1) from (select * from A union all select * from B) T