--1 查询表中所有信息 其中*代表所有列select*from people
--2 查询people表中某些列select PeopleName,PeopleSex,PeopleBirth,PeopleSalary,PeoplePhone from people
--3 查询people表中某些列 以指定名字显示出来select PeopleName as 姓名,PeopleSex as 性别,PeopleBirth as 出生日期,PeopleSalary as 薪水,PeoplePhone as 电话号码 from people
--不用as 也是可以的select PeopleName 姓名,PeopleSex 性别,PeopleBirth 出生日期,PeopleSalary 薪水,PeoplePhone 电话号码 from people
--4 查询所有员工城市分布,且不想要重复的数据显示--使用distinct 关键字去约定不显示重复城市selectdistinct(PeopleAddress)from people
--5 假设 准备加工资--涨薪20% 查看加工资后的员工数据select PeopleName,PeopleSex,PeopleSalary=PeopleSalary*1.2from people
条件查询
--1 条件查询 --查询性别为女的员工信息select*from people where PeopleSex='女'--2 查询工资大于等于50000的所有员工信息select*from people where PeopleSalary>=50000--3 当有多个条件使用and将条件联合起来--查询性别为女 且 月薪大于50000的人的信息select*from people where PeopleSex='女'and PeopleSalary>=50000--4 当查询条件复杂可以用括号括起来--查询月薪大于50000,或者月薪大于20000的女生--select * from People where 条件1 or 条件2select*from People where PeopleSalary>=50000or(PeopleSex='女'and PeopleSalary>20000)--5 查询薪资在20000到50000之间的人员信息select*from people where PeopleSalary>=20000and PeopleSalary<=50000--像这种范围,也可以使用between....and...去查询,效果是一样的select*from People where PeopleSalary between20000and50000
查询空内容
--1 查询地址没有填写的员工--查询字段内容为空的时候,不可以使用= 去判断内容是否为空--有专门的使用的是isselect*from people where PeopleAddress isNULL--查询地址不为空的员工信息select*from people where PeopleAddress isnotNULL--NULL和空字符串是不一样的,在插入的时候直接不插入该列就是空值,如果插入的时候写了该列,插入数据给的是''--这相当于给的是一个空字符串,所以在查询的时候,查询空字符串应该使用等于,如下所示select*from poeple where PeopleAddress =''
子查询
--1 查询出 比小刘工资高的员工的信息--先查询出小刘那一行的工资这一列,要确保比对的数据只有一个,要不然是不被允许的--当报错说子查询的值不只一个的时候,就要检查约束的条件是不是不够多--使用>去比较的时候 保证子查询出来的结果是一个可比较的值select*from people where PeopleSalary >(select PeopleSalary from people where PeopleName='小刘'and RankID=1)--2 查询和小陈一个城市的人的信息select*from people where PeopleAddress =(select PeopleAddress from people where PeopleName='小陈')
模糊查询
--模糊查询--使用like关键字和一些通配符去查询--% 代表匹配0个字符,1个字符,或者多个字符-- ——代表匹配的只有一个字符--[]代表匹配范围内--[^]代表不在范围内--1 查询叫 某某刘的员工信息select*from people where PeopleName like'%刘'--2 查询people中名字中含有白的 但是不知道白在名字的哪个字select*from people where PeopleName like'%白%'--3 查询出名字中含有’白‘或者’拜‘的员工信息select*from people where PeopleName like'%白%'or PeopleName like'%拜%'--4 查询出名字是刘的员工 且名字是两个字,姓啥咱不管select*from people where PeopleName like'_刘'