SQL server 查询常用语句 2019.3.20
-
select ...列名 from 表名
投影查询
select sno num,2019-sage as birthday // 给列起别名
from student;
在每个学生姓名后面显示 2017
select sname,'2017'
from student;
无条件选择
select *
from student;
作用在单列上,空值不计,重复值重复计,
对元组技术,某个元组一个或部分列为空不影响计数
select COUNT(*)
from student;
查询选修了课程的学生的学号
查询满足条件的元组
查询所有年龄在20岁以下的
select sno,sname
frome student
where sage>20
distinct 严格模式,只要有一个满足条件就可以
from student
where sdept in('sd','sd','s');
等同于or
模糊查询
_通配符
%转义字符
where ssex like '123_sd' escape \
指定\为转义字符