易截截图软件、单文件、免安装、纯绿色、仅160KB

常用SQL面试题 (二)

Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
  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、查询平均成绩大于60分的同学的学号和平均成绩;
    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、查询学过“001”并且也学过编号“002”课程的同学的学号、姓名;
  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、查询课程编号“002”的成绩比课程编号“001”课程低的所有同学的学号、姓名;
  Select S#,Sname from (select Student.S#,Student.Snam


相关文档:

sql查询练习

例 34  找出年龄超过平均年龄的学生姓名。
SELECT SNAME
from STUDENTS
WHERE AGE >
      (SELECT  AVG(AGE)
        from   STUDENTS)
例 35  找出各课程的平均成绩,按课程号分组,且只选择学生超过 3 人的课程的成 ......

SQL 优化技巧

1 避免无计划的全表扫描
  如下情况进行全表扫描:
-          该表无索引
-          对返回的行无人和限制条件(无Where子句)
-          对于索引主列(索引的第一 ......

SQL Server索引统计信息未及时更新,导致排序混乱

今天,遇到了这样的一个例子:
SQL Server索引统计信息未及时更新,导致排序混乱
我们知道,在sql
server上创建索引后,同时会对该索引上的值进行排序,但对于新增加的值,如果未能及时更新统计信息,将有可能导致排序的混乱,也就是没有排序。
这是产生问题的语句:
Select * from V_L_IcStockProInEntry Where FInt ......

同一表多字段同时重复记录的SQL查询及处理数

同一表多字段同时重复记录的SQL查询及处理数
比如现在有一人员表 (表名:peosons)
若想将姓名、身份证号、住址这三个字段完全相同的记录查询出来
select p1.* from persons p1,persons p2 where p1.idp2.id and p1.cardid = p2.cardid and p1.pname = p2.pname and p1.address ......

更改SQL 2005的登陆方式

如果你的身份验证方式为Windows集成身份验证更改为混合方式的身份验证,需要在SQL Server Configuration Management中,把TCP/IP的活动启用,也就是第一个选择的地方,选择启用。并且使用集成身份验证方式登录后,在数据库服务器上选择属性,把安全性下的WINDOWS模式改为SQL与WINDOWS模式 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号