幻想编程

从头到脚学Sql语言(5)

时间:14-03-09 20:34:51点击:393

下面介绍between。。。and。。。

查询分数80到90分之间的学生

select * from Student where score between 80 and 90


反之,查询分数不在80到90分之间学生是

select * from Student where score not between 80 and 90

介绍top

查询学生表前3名学生

select top 3 * from Student


查询学生表总分用sum() sql函数

select sum(score) from Student

结果显示425

查询学生表平均分用avg()函数

select avg(score) from Student

结果显示85

查询学生表有多少个学生,也就是查询表中记录数,用count()函数

select count(*) from Student

结果显示5

查询最高分,用max()函数

select max(score) from Student

结果显示100

查询最低分,用min函数

select min(score) from Student

结果显示55

like 关键字用于模糊查询

查询姓名名字尾部为 红 学生

select * from Student where name like '%红'

in 操作符允许我们在 where 子句中规定多个值。

查询名字是小明和小红的学生

select * from Student where name in ('小明','小红')