我们今天学习了sql server高级查询语句:
1.--select查询
Select *from student;
2.--all查询所有
Select all sex from student;
3.--Distinct 过滤重复
Select distinct set from student;
4.--cont 统计
Select count (*) from student;
Select count(sex) from student;
Select count(distinct sex)from student;
5.--top 取前条记录
Select top 3*from student;
6.--alias column name 列重命名
Select id as 编号,name’名称’,sex 性别 from student,
7.--Alias table name 表重命名
Select id ,name,s.id,s.name from student s;
8.-column 列运算
Select (age+id) col from stuent;
Select s.name+’-’+c.name from classes c,student s where s.cid=c.id;
声明:此篇文档时来自于【狗刨学习网】社区-unity极致学院,是网友自行发布的Unity3D学习文章,如果有什么内容侵犯了你的相关权益,请与官方沟通,我们会即时处理。
9.--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;
10.--and 并且
Select *from student where id>2 and sex =1;
11.--or 或者
Select*from studnt where id>2 and sex=1;
12.--beltween...and.....相当于并且
Select *from student where id between2 and 5;
Select *from student where id between2 and 5;
13.Like-模拟查询
Select *from student where name like %a%;
Select *from student where name like %[a][0]%;
Select* from studnt where name like %a%;
Select* ftom student where name like ja%;
14.--还学习了内连接查询语句
Select u.name,s.grade from score as s inner join users as u on s.uid=u.id
Select u.name,s grade from score as s inner join user as u on s.uid=u.id
15.--左外连接查询语句
Select u.name,s.grade from score as s inner left join users as u on s.uid=u.id
Select u name,s.grade from users as u inner lest join score as s on s.uid=u.id
16.--右外连接查询语句
select u.name,s.grade from score as s inner right join users as u on s.uid=uid
Select u name,s.grade from users as u inner right join score as s on s.uid=u.id