Select sno,sname,avg(sage) From student 改正: Select avg(sage) From student Select 目标列表达式 From 表名 Where 选择条件 选择条件的展开
比较运算符:列名1='值1' = , < , > , <= , >= ,<>,!=
多条件连接符:and 多个条件同时成立 列1='值1' and 列2='值2'
Or 多条件之一成立 列1='值1' or 列2='值2' 在某个范围内的查询 列1 between 值1 and 值2 包含边界值 值1和值2 在某个集合之内的查询 列1 in('值1','值2',??) 模糊查询 列 like '匹配串' 通配符:4种 在匹配串中使用
(1)- 下划线 表示单个字符或单个汉字
例:1,a,啊, (空格), (不能代表空) (2)% 百分号 表示0个或多个字符 (3)[单个字符的取值范围] [0-9] [a-z] (4)[^] :某单个字符不在该范围内 查询所有女同学的信息 Select * From student Where ssex '女'
查询所有年龄为20岁的男同学的学号,姓名 select sno,sname from student
where sage=20 and ssex='男'
查询所有年龄为20或者性别为男的学生信息 select * from student
where sage=20 or ssex='男'
查询年龄在19到20之间的学生的学号,姓名,年龄select sno,sname,sage from student
where sage between 19 and 20
查询年龄在19到20之间的学生的学号,姓名,年龄select sno,sname,sage from student
where sage in(19,20)
查询年龄在19到20之间的学生的学号,姓名,年龄 select sno,sname,sage from student
where sage=19 or sage=20
查询年龄在19到20之间的学生的学号,姓名,年龄select sno,sname,sage from student
where sage>=19 and sage<=20 空值的判断 列 is null
查询没有课时的课程的课程号和课程名 Select cno '课程号',cname'课程名' From course Where ctime is null
查询已经填写了课时的课程的课程号和课程名 Select sno '课程号',cname'课程名' From course
Where ctime is not null
查询名字第二个字是“天”的同学的信息 Select * From student
Where sname like '_天__'
查询名字第二个字是\天\的同学信息
Select * From student
Where sname like '_天%'
查询课程表中与\网络\有关的课程信息 Select * From course
Where cname like '%网络%' 查询113342班同学的基本信息 Select * From student
Where sno like '113342%' 查询113342班男同学的基本信息 Select * From student
Where sno like '113342%' and ssex='男'
查询113342班年龄在18到20岁之间的男同学的基本信息 Select * From student
Where sno like '113342%' and ssex='男' and Sage between 18 and 20 连接查询
1 等值连接或者非等值连接 Select 表1.列名1,表2.列2
From 表1,表2 Where 连接条件 连接条件展开:
表1.列1=表2.列2(等值连接) 表1.列1>表2.列2(非等值连接) 内连接(等价于第一种) Select 目标列
From 表1 inner join 表2 on(表1和表2的连接条件) inner join 表3 on(表2和表3的连接条件) Where 选择条件
修改课程表结构,增加一个新列先修课,cpn Varchar(10) 可以为空 Alter table course Add cpno Varchar(10) 数据更新
Update 表名 set 列=值 where 选择条件
(1)将数据库程序设计这门课程的先修课好修改为83103008 update course set cpno='83103008'
where cname='数据库程序设计' (2)将每个同学的年龄增加一岁 Update student Set sage=sage+1
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库使用sql语言创建数据库的方法(4)在线全文阅读。
相关推荐: