我有两个表 
t1           t2
ID           学生ID
学生ID       姓名
科目
成绩现在想查询有三个科目成绩在90以上的学生,
SQL该怎么写呢?

解决方案 »

  1.   

    select distinct studentid 
    from t2,t1
    where 科目1>90 and 科目2>90 and 科目3>90 and t1.studentid=t2.studentid
      

  2.   


    Select 学生ID ,count(学生ID) as score from t1 group by 学生ID HAVING 成绩>90
    and Count(学生ID) > 2 
      

  3.   

    SELECT 查询11.学生ID, t2.姓名
    FROM t2 INNER JOIN (SELECT t1.学生ID, Count(t1.成绩) AS 成绩之Count
    FROM t1
    WHERE (((t1.成绩)>90))
    GROUP BY t1.学生ID
    HAVING (((Count(t1.成绩))>=3))) 
    查询11 ON t2.学生ID = 查询11.学生ID;
      

  4.   

    SELECT 查询11.学生ID, t2.姓名
    FROM t2 INNER JOIN (SELECT t1.学生ID, Count(t1.成绩) AS 成绩之Count
    FROM t1
    WHERE (((t1.成绩)>90))
    GROUP BY t1.学生ID
    HAVING (((Count(t1.成绩))>=3))) 
    查询11 ON t2.学生ID = 查询11.学生ID;
      

  5.   

    select b.学生ID,b.姓名
    from ( select 学生ID,科目,account = sum((case when 成绩 > 90 then 1 else 0 end)) 
    from t1  
    group by 学生ID,科目) a, t2 b
    where a.account >=3 and a.学生ID = b.学生ID