1.  select distinct name from 班级A where age>202.select  name from 班级A where age>20
union
select  name from 班级B where age>20

解决方案 »

  1.   

    第一个SQL:
    select name from 班级A where age>20 group by name having count(*)>1 select * from 班级A a,
    (select name from  班级A group by name having count(*)>1) b 
      where a.name = b.name and a.age > 20
      

  2.   

    呵呵,不好意思,写错了。sasacat那种写法就可以了,简单明了
      

  3.   

    select name from  班级A where name in (select name from  班级A where age>20) group by name having count(*)>1select name from  (select * from 班级A union all select * from 班级B) where name in (select name from  (select * from 班级A union all select * from 班级B) where age>20) group by name having count(*)>1
      

  4.   

    重名的name,sasacat(傻傻猫)的会把不重名的查出来
      

  5.   

    现在公布正确答案
    第一种
    select distinct a.name from 班级A a,
    (select name from  班级A group by name having count(*)>1) b 
      where a.name = b.name and a.age > 20第二种
     select * from 班级A a, 班级B b
        where a.name = b.name and ((a.age > 20) or (b.age > 20))
      

  6.   

    呵,不好意思。我的也错了
    这样就对了
    SELECT DISTINCT NAME
               FROM 班级A
              WHERE NAME IN (SELECT   NAME
                                 FROM 班级A
                             GROUP BY NAME
                               HAVING COUNT (*) > 1) AND age > 20要两个表的就这样union就好了
      

  7.   

    waterfirer(水清) 是啊,是我看错了。不过我想出来的时候你已经....
      

  8.   

    呵呵,这下总不会有错了吧
    PS:waterfirer(水清)经常看到你啊