SQL语句中的查询操作
2016-04-01 22:03
323 查看
单表查询
1.查询全体学生地 学号和姓名
2.查询全体学生的详细记录
3.查询经过计算的值(查询全体学生的姓名及出生年份)
选择表中的若干元祖
1.消除取消重复的行
2.查询满足条件的元祖
比较运算符 =,>, <, >=, <=, !=, <>, !>, !<, NOT +
确定范围 between and, not between and
确定集合 in,not in
字符匹配 like, not like
空值 is null, is not null
多重运算符(逻辑运算符) and ,or, not
比较大小
查询计算机科学系全体学生的名单
注意该查询的运算过程 :对Student表进行全表扫描,取出一个元组,检查该元组在Sdept列的值是否等于‘CS’。如果相等,取出Sname列的值形成一个新的元组输出,否则跳出该元组,取下一个元组。(from->where->select)面试可能会问。。。。
查询所有年龄在20岁以下的学生姓名及年龄
查询考试成绩不及格的学生的学号
确定范围
查询年龄在20-23岁之间的学生姓名、系别和年龄
查询年龄不在20-23岁之间的学生姓名、系别和年龄
确定集合
查询计算机科学系(CS)、数学系(MA)和信息系(IS)学生的姓名和性别
查询既不是计算机系,数学系,也不是信息系的学生姓名和性别
1.查询全体学生地 学号和姓名
select Sno,Sname from Student;
2.查询全体学生的详细记录
select * from Student;
3.查询经过计算的值(查询全体学生的姓名及出生年份)
select Sname, 'Year of Birth;',2004-Sage,LOWER(Sdept) from Student;
选择表中的若干元祖
1.消除取消重复的行
select distinct Sno from SC;
2.查询满足条件的元祖
比较运算符 =,>, <, >=, <=, !=, <>, !>, !<, NOT +
确定范围 between and, not between and
确定集合 in,not in
字符匹配 like, not like
空值 is null, is not null
多重运算符(逻辑运算符) and ,or, not
比较大小
查询计算机科学系全体学生的名单
select Sname from Student where Sdept='CS'
注意该查询的运算过程 :对Student表进行全表扫描,取出一个元组,检查该元组在Sdept列的值是否等于‘CS’。如果相等,取出Sname列的值形成一个新的元组输出,否则跳出该元组,取下一个元组。(from->where->select)面试可能会问。。。。
查询所有年龄在20岁以下的学生姓名及年龄
select Sname,Sage from Student where Sage<20;
查询考试成绩不及格的学生的学号
select distinct Sno from SC where Grade<60;
确定范围
查询年龄在20-23岁之间的学生姓名、系别和年龄
select Sname,Sdept,Sage from Student where Sage between 20 and 23;
查询年龄不在20-23岁之间的学生姓名、系别和年龄
select Sname,Sdept,Sage from Student where Sage not between 20 and 23;
确定集合
查询计算机科学系(CS)、数学系(MA)和信息系(IS)学生的姓名和性别
select Sname,Ssex from Student where Sdept in ('CS','MA','IS');
查询既不是计算机系,数学系,也不是信息系的学生姓名和性别
select Sname,Ssex from Student where Sdept not in ('CS','MA','IS');
相关文章推荐
- SQL中的三值逻辑
- SQL Server 作业批量停止
- 结束SQL阻塞的进程
- 动态生成SQL Server视图作业
- SQL Server 语句操纵数据库
- SQL(结构化查询语句)
- oracle sql日期比较
- linux快速部署mysql服务器
- sql 存储过程分页
- 在WINXP系统上安装SQL Server企业版的方法
- 通过批处理调用SQL的方法(osql)
- SQL Server 存储过程的分页
- ASP程序与SQL存储过程结合使用详解
- SQL SERVER编写存储过程小工具
- 防御SQL注入攻击时需要注意的一个问题
- PostgreSQL教程(十九):SQL语言函数
- SQL Server复制需要有实际的服务器名称才能连接到服务器
- SQL Server 2000向SQL Server 2008 R2推送数据图文教程