50条常用sql语句
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“”课程比“”课程成绩高的所有学生的学号;
SELECT a.S# from (SELECT s#,score from SC WHERE C#='001') a,
(SELECT s#,score from SC WHERE C#='002') b
WHERE a.score>b.score AND a.s#=b.s#;
2、查询平均成绩大于分的同学的学号和平均成绩;
SELECT S#,avg(score)
from sc
GROUP BY S# having avg(score) >60;
3、查询所有同学的学号、姓名、选课数、总成绩;
SELECT Student.S#,Student.Sname,count(SC.C#),sum(score)
from Student left Outer JOIN SC on Student.S#=SC.S#
GROUP BY Student.S#,Sname
4、查询姓“李”的老师的个数;
SELECT count(distinct(Tname))
from Teacher
WHERE Tname like '李%';
5、查询没学过“叶平”老师课的同学的学号、姓名;
SELECT Student.S#,Student.Sname
from Student
WHERE S# not in (SELECT distinct( SC.S#) from SC,Course,Teacher WHERE SC.C#=Course.C# AND Teacher.T#=Course.T# AND Teacher.Tname='叶平');
6、查询学过“”并且也学过编号“”课程的同学的学号、姓名;
SELECT Student.S#,Student.Sname from Student,SC WHERE Student.S#=SC.S# AND SC.C#='001'and exists( SELECT * from SC as SC_2 WHERE SC_2.S#=SC.S# AND SC_2.C#='002');
7、查询学过“叶平”老师所教的所有课的同学的学号、姓名;
SELECT S#,Sname
from Student
WHERE S# in (SELECT S# from SC ,Course ,Teacher WHERE SC.C#=Course.C# AND Teacher.T#=Course.T# AND Teacher.Tname='叶平' GROUP BY S# having count(SC.C#)=(SELECT count(C#) from Course,Teacher WHERE Teacher.T#=Course.T# AND Tname='叶平'));
8、查询课程编号“”的成绩比课程编号“&rdqu
相关文档:
==============================================
第1讲
在线观看: http://www.boobooke.com/v/bbk1389
视频下载: http://www.boobooke.com/v/bbk1389.zip
第2讲
在线观看: http://www.boobooke.com/v/bbk1390
视频下载: http://www.boobooke.com/v/bbk1390.zip
第3讲
在线观看: http ......
String keyword = request.getParameter("keyword");
String timeRange = request.getParameter("timeRange");
String type = request.getParameter("type");
StringBuffer sql = new StringBuffer();
sql.append("use webstation_leadall s ......
“经过测试我们发现SQL Server 2008当中的备份压缩功能可以1-3倍的压缩比,从而极大的减少备份所需的磁盘空间。”Alexey Yeltsov, 微软系统管理员主管。
微软在全世界共有6万多名员工,在2006年的财政收入超过了500亿美金,与此同时也产生了大量内部数据,公司希望对这些数据进行集中以便提供客户的集成化视图。 ......
列出TableA中有的而TableB中没有, 以及B中有而A中没有的记录:
其中两个表的结构相同,选择的Key可以多个
Select Key from
( select * from TableA
Union select * from TableB
)
group by Key
having count(Key)=1
列出TableA中有的而TableB中没有的记录:
Select Key from
( (select * from TableA
Un ......