文章目录
投影查询
选中表中指定的列
use teaching
select sname,ssex,specialty from student
use teaching
select * from course
use teaching
select distinct specialty from student
use teaching
select top 3 * from course
use teaching
select top 50 percent * from course
改变查询结果标题的显示
use teaching
select sno as 学号,sname as 姓名 from student
use teaching
select 学号=sno,姓名=sname from student
use teaching
select sno 学号,sname 姓名 from student
计算列值
use teaching
select sno,cno,score150=score*1.5 from sc
选择查询
使用关系表达式
use teaching
select * from sc where score>=60
使用逻辑表达式
use teaching
select * from student
where specialty =‘计算机’ and ssex=‘男’
use teaching
select * from student
where specialty =‘计算机’ or ssex=‘男’
使用between 关键字
use teaching
select * from sc
where score between 80 and 100
使用in关键字
use teaching
select sname,ssex,sno,specialty from student
where specialty in(‘计算机’,‘通信’)
使用Like关键字
use teaching
select * from student
where name like ‘张%’
使用IS(NOT)NULL查询
use teaching
select * from sc where score IS NULL
复合条件查询
use teaching
select * from student
where ssex=‘女’ and (specialty =‘计算机’ or sepcialty=‘通信’)
聚合函数查询
use teaching
select avg(score) as 平均成绩 from sc
use teaching
select count(distinct specialty) as 专业种类数
from student
use teaching
select avg(score) as 平均成绩 from sc
where sno=‘1302001’