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

50个常用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 UPDATE如何工作

在SQL UPDATE语句中,对换两个变量的值,不需要临时变量。=右侧的值在整个UPDATE语句中都是一致的;所有的更新同时发生,而不是一个接着一个发生。
例如:
UPDATE offenceTeam
        SET goalShooter=wingAttack,
          & ......

Maximizing SQL*Loader Performance


Maximizing SQL*Loader Performance 
SQL*Loader is flexible and offers many options that should be considered to maximize the speed of data loads.  These include:
 
●     Use Direct Path Loads - The conventional path loader essentially loads the data by usin ......

sql语句 访问不同数据库服务器中的数据库对象的方法

 在我们做数据库程序开发的时候,经常会遇到这种情况:需要将一个数据库服务器中的数据导入到另一个数据库服务器的表中。通常我们会使用这种方法:先把一个数据库中的数据取出来放到某出,然后再把这些数据一条条插入到目的数据库中,这种方法效率较低,写起程序来也很繁琐,容易出错。另外一种方法是使用bcp或BULK IN ......

sql server 的 money类型

sql server的 money 类型其实就是小数类型 decimal ,我不喜欢用它,因为有一次什么工具生成,发现它自动把money类型转换成了decimal类型了,与其让它转,还不如自己设计数据库时将货币类型字段设置为 decimal 类型不就得了,废那事干嘛!   字节数 长度(小数点前.小数点后) ......

如何有效的防止SQL连接字符串注入

 概念:在编写安全代码时,最重要的规则之一就是“绝对不要盲目的相信用户的输入”。
利用ADO.NET 2.0的SqlConnectionStringBuilder类生成数据库连接字符串,它可以有效的防止“SQL连接字符串恶意注入”,因为这个类是专门为SQL SERVER设计的所以;它兼容旧式关键字。关于如何使用SqlConnectionS ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号