有这样一张表张三 数学 90
张三 语文 75
李四 数学 70
李四 语文 95
王五 数学 99
王五 语文 90
王五 英语 100要用一条语句查询出所有科目都唱过80分的学生名字。请高手赐教,急。谢谢。

解决方案 »

  1.   

    select distinct name from temp
    minus
    select distinct name from temp where fsh < 80
      

  2.   

    你提供的信息不够足,是不是有个学科的字典
    还是我根据你的表distinct学科就是字典吗
    要不没法写
      

  3.   

    select name
    from 
    (select name,count(course) t1,count(case when score>80 then 1 else 0 end) t2
    from table_name
    group by name)
    where t1=t2
      

  4.   

    select name
    from  
    (select name,count(course) t1,sum(case when score>80 then 1 else 0 end) t2
    from table_name
    group by name)
    where t1=t2
      

  5.   

    SELECT DISTINCT(t1.xm) 
    FROM test111 t1
    WHERE t1.xm NOT IN (
      SELECT t2.xm 
      FROM test111 t2
      WHERE t2.cj <= 80
    )看这个咋样
      

  6.   

    这样:假设该表为Table 有3列:姓名、科目、分数。 可以使用以下sql满足你的要求。select 姓名,count(1) from Table 
         where 分数>=80 group by 姓名 having count(1)=科目数(这是个数字,有几科就等于几
      

  7.   

    Phoenix_99 的解答:
    select distinct name from temp
    minus
    select distinct name from temp where fsh < 80;这才是高手的解答,用集合的方式思考问题!高手啊!
      

  8.   

    select name from table group by name having min(score)>80
      

  9.   

    minitoy 的解答最好:
    select name from table group by name having min(score)>80;
      

  10.   

    Minitoy 膜拜一个~!
    select distinct t1.name 
    form tmp_table t1
    where not exists(
    select * from tmp_table t2
    where t1.name=t2.name and t2.score<80);
      

  11.   

    select distinct(s1.name) from s s1 
    where not exists (
        select score from s s2 where s1.name=s2.name and s2.score<80
    )