select name from
(
select distinct name from tb where subject = '语文' and  > 80
union all
select distinct name from tb where subject = '数学' and  > 80
) t
group by name having count(*) = 2
select name from
(
select distinct name from tb where subject = '语文' and  >= 80
union all
select distinct name from tb where subject = '数学' and  >= 80
) t
group by name having count(*) = 2

解决方案 »

  1.   


    select  distinct name from tablename where id in (select id from tb where subject='语文' and >80)
    and id in (select id from tb where subject='数学' and >80)
      

  2.   

    select  distinct name from tb where id in (select id from tb where subject='语文' and >80)
    and id in (select id from tb where subject='数学' and >80)
      

  3.   

    select name from table a where exists(select top 1 * from table where a.name = name and subject ='语文' and isnull(,0)
     > 80) and a.subject ='数学' and (isnull(,0) > 80)
      

  4.   

    select name from table a where exists(select top 1 * from table where a.name = name and subject ='语文' and isnull(,0)
    > 80) and a.subject ='数学' and (isnull(,0) > 80)
      

  5.   


    select name
    from tb 
    where subject='语文' or subject='数学' and >=80
    group by name 
    having count(*)=2
      

  6.   

    create table #tb(id int,name varchar(10),subject varchar(10), numeric(5,2))
    insert into #tb(id,name,subject, )
    select '1','小王','语文','80'
    union all select '2','小王','语文','85'
    union all select '3','小李','数学','82'
    union all select '4','小李','数学','70'select name 
    from #tb 
    where subject='语文' or subject='数学' and >=80 
    group by name 
    having count(*)=2 /*
    小王
    */
      

  7.   

    select distinct name from Table_1 where id in
    (
    select id from Table_1 where subject in('语文','数学') and  > 80
    )不知道是不是你想要的结果?
      

  8.   

    SELECT mt1.name
      FROM _table mt1
     WHERE mt1.subject = '语文'
       AND mt1. > 80
       AND mt1.name IN (
           SELECT mt2.name
             FROM _table mt2
            WHERE mt2. > 80
              AND mt2.subject = '数学')
      

  9.   


    select name from
    (
    select *
    ,case when subject='语文' and  >=80 then 1 else 0 end as yw
    ,case when subject='数学' and  >=80 then 1 else 0 end as sx from tt
    ) n
    group by name
    having SUM(yw) + SUM(sx) =2
      

  10.   

    有一个表: 
    id  name  subject  
    1    小王    语文    80 
    2    小王    语文    85 
    3    小李    数学    82 
    4    小李    数学    70 要求:查询到语文和数学成绩都大于80分的人名。select distinct name from 表名 
                                  where sno in( 
                                            select sno from 表名
                                                  where >80 and 
                                            subject in(语文) 
                                           )
                               and sno in  ( 
                                             select sno from 表名
                                                   where >80 and 
                                             subject in(数学)
                                            )
      

  11.   

    select 人名 from table where 人名
    in(select 人名 from 表名 here >80 and subject in(语文)) 
    and sno in  ( select 人名 from 表名 where >80 and subject in(数学))