简单查询

投影查询

选中表中指定的列

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’

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值