1. 程式人生 > >面試-一道經典的sql語句題

面試-一道經典的sql語句題

原文地址:http://blog.csdn.net/xiaoyida11/article/details/22441617

給一個班級成績表 student (name,subject,score) , 


查詢出所有總分數>600分的學員

[sql] view plain copy  print?在CODE上檢視程式碼片派生到我的程式碼片
  1. selectname,sum(score) from student groupbynamehavingsum(score)>600;  
在總分大於600的基礎上,去掉不及格的學員並按總分倒序排列。 [sql] view plain copy  print?在CODE上檢視程式碼片派生到我的程式碼片
  1. select
    name,sum(score) s from student groupbynamehavingsum(score)>600 andmin(score)>60 orderby s desc;  

找出有三科掛了的學員
[sql] view plain copy  print?在CODE上檢視程式碼片派生到我的程式碼片
  1. selectnamefrom student  where score<60 groupbynamehavingcount(name)>=3;