S(sno,sname)
C(cno,cname)
SC(sno,cno,grade)这是三张表,大家应该都知道吧写出每门课程成绩大于90分的人数的select语句,我看到答案了,但是思路还是比较混乱,请大牛们帮我理一理思路地给出答案比如,第一步,想到什么
      第二部,想到什么
      然后。
尽量把思路写出来,非常地感谢啦!!!!

解决方案 »

  1.   

    给出建表create语句 和测试数据insert脚本,我才能帮你好分析不是?
      

  2.   

    select c.cname, sum(case when sc.grade>=90 then 1 else 0 end) as upper_90_num
    from c join sc on c.cno=sc.cno
    group by c.cname;
      

  3.   

    每门课程成绩大于90分的人数.
    解析:
    每门课程:就是按照课程分类,group by cno。
    成绩大于90分,where子句后面grade > 90。
    人数:很明显这个是统计人数的多少,用count()函数。select cno, count(1) from sc where grade > 90 group by cno;
      

  4.   

    逆向法1.从 sc 表中 找出 存在 课程成绩小于90 分的 sno。2.从sc 表中剔除 第一步得到的sno,剩下的就是所有成绩大于90分的。3. count求数量。sql如下:
    select count(distinct sno) cnt
      from sc t
     where not exists (select 1
              from sc t1
             where t1.grade < 90
               and t.sno = t1.sno);
      

  5.   

    select * from S
    where Sno not in( select Sno from SC where SC.grade<90 and SC.Sno =S.Sno)