查询语句
关键字:SELECT
查询所有:
Select * from 表名
Select * from stuInfo
查询部分字段
Select 字段1,字段2,字段3… from 表名 Select stuName,stuSex from stuInfo
插入语句
关键字:insert
插入语句:
insert into 表名 (字段1,字段2…) Values (值1,值2…)
更新语句
关键字:update
更新语句:
update 表名 Set 字段1=‘值1’,字段2=‘值2’Where 字段3=‘值3’
删除语句
关键字:delete
删除语句:
Delete * From 表名 where 字段1=‘值1’
去重复行
关键字:DISTINCT
去重复行:
select distinct 列名1 from 表名
select distinct depart from teacher
注意:DISTINCT必须放在所有列名前面
重命名语句
关键字:AS
select Sno as '学号', Sname as '姓名', Ssex as '性别', Sbirthday as'出生日期', Class as'班号' from student
区间语句
关键字:between
Select * from score where degree between 60 and 80
指定条件语句
关键字:IN
select * from score where degree in (85,86,88)
AND语句
关键字:AND
select * from score where degree>=60 and degree<=80
OR语句
关键字:OR
Select * from student where class='95031' or Ssex='女'
排序语句
关键字:order by
题目:以Class降序查询Student表的所有记录
select * from student order by class desc
注:
ASC为升序 默认不写; DESC为降序
汇总语句
关键字:count(*)
题目:查询“95031”班的学生人数。
select count(*) as CNT from student where class='95031';
求一列的最大值
关键字:max
题目:查询Score表中的最高分
select max(degree) From Score
求一列的最小值
关键字:min
题目:查询Score表中的最低分
select min(degree) From score
求平均值
关键字:avg(字段名)
题目:查询‘3-105’号课程的平均分。
select avg(degree) as 课程平均分 from score where cno='3-105';
分组语句(having是条件)
关键字:group by(字段名) having 条件
题目:查询Score表中至少有5名学生选修的并以3开头的课程的平均分数。
Select cno, avg(degree) from score where cno like'3%' group by cno having count(*) >5;