SQL语句中的查询操作

来源:互联网 发布:s7200梯形图编程实例 编辑:程序博客网 时间:2024/05/16 09:18

单表查询

1.查询全体学生地 学号和姓名

select Sno,Snamefrom Student;

2.查询全体学生的详细记录

select *from Student;

3.查询经过计算的值(查询全体学生的姓名及出生年份)

select Sname, 'Year of Birth;',2004-Sage,LOWER(Sdept)from Student;

选择表中的若干元祖

1.消除取消重复的行

select distinct Snofrom SC;

2.查询满足条件的元祖

比较运算符  =,>, <, >=, <=, !=, <>, !>, !<, NOT +

确定范围 between and, not between and

确定集合 in,not in

字符匹配  like, not like

空值 is null, is not null

多重运算符(逻辑运算符) and ,or, not

比较大小

查询计算机科学系全体学生的名单

select Snamefrom Studentwhere Sdept='CS'

注意该查询的运算过程 :对Student表进行全表扫描,取出一个元组,检查该元组在Sdept列的值是否等于‘CS’。如果相等,取出Sname列的值形成一个新的元组输出,否则跳出该元组,取下一个元组。(from->where->select)面试可能会问。。。。

查询所有年龄在20岁以下的学生姓名及年龄

select Sname,Sagefrom Studentwhere Sage<20;

查询考试成绩不及格的学生的学号

select distinct Snofrom SCwhere Grade<60;

确定范围

查询年龄在20-23岁之间的学生姓名、系别和年龄

select Sname,Sdept,Sagefrom Studentwhere Sage between 20 and 23;

查询年龄不在20-23岁之间的学生姓名、系别和年龄

select Sname,Sdept,Sagefrom Studentwhere Sage not between 20 and 23;

确定集合

查询计算机科学系(CS)、数学系(MA)和信息系(IS)学生的姓名和性别

select Sname,Ssexfrom Studentwhere Sdept in ('CS','MA','IS');

查询既不是计算机系,数学系,也不是信息系的学生姓名和性别

select Sname,Ssexfrom Studentwhere Sdept not in ('CS','MA','IS');


0 0
原创粉丝点击