1 / 38
文档名称:

SQL-Server-常用语句.docx

格式:docx   大小:85KB   页数:38页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

SQL-Server-常用语句.docx

上传人:iris028 2021/1/8 文件大小:85 KB

下载得到文件列表

SQL-Server-常用语句.docx

相关文档

文档介绍

文档介绍:SQL Server T-SQL高级查询
高级查询在数据库中用得是最频繁的,也是应用最广泛的。
Ø 基本常用查询
--select
select * from student;
 
--all 查询所有
select all sex from student;
 
--distinct 过滤重复
select distinct sex from student;
 
--count 统计
select count(*) from student;
select count(sex) from student;
select count(distinct sex) from student;
 
--top 取前N条记录
select top 3 * from student;
 
--alias column name 列重命名
select id as 编号, name '名称', sex 性别 from student;
 
--alias table name 表重命名
select id, name, , from student s;
 
--column 列运算
select (age + id) col from student;
select + '-' + from classes c, student s where = ;
 
--where 条件
select * from student where id = 2;
select * from student where id > 7;
select * from student where id < 3;
select * from student where id <> 3;
select * from student where id >= 3;
select * from student where id <= 5;
select * from student where id !> 3;
select * from student where id !< 5;
 
--and 并且
select * from student where id > 2 and sex = 1;
 
--or 或者
select * from student where id = 2 or sex = 1;
 
--between ... and ... 相当于并且
select * from student where id between 2 and 5;
select * from student where id not between 2 and 5;
 
--like 模糊查询
select * from student where name like '%a%';
select * from student where name like '%[a][o]%';
select * from student where name not like '%a%';
select * from student where name like 'ja%';
select * from student where name not like '%[j,n]%';
select * from student where name like '%[j,n,a]%';
select * from student where name like '%[^ja,as,on]%';
select * from student where name like '%[ja_on]%';
 
--in 子查询
select * from student where id in (1, 2);
 
--not in 不在其中
select * from student where id not in (1, 2);
 
--is null 是空
select * from student where age is null;
 
--is not null 不为空
select * from student where age is not null;
 
--order by 排序
select * from student order by name;
select * from student order by name desc;
selec