门户网站建设系统,上海网站设计多少钱,做网站公司价格,pc网站如何做移动适配DQL学习#xff08;Data Query Language数据查询语言#xff09;
DQL-语法#xff1a; select 字段列表 from 表名列表 where 条件列表 group by 分组字段列表 having 分组后条件别表 order by 排序字段列表 limit 分页参数 基本查询条件查询#xff08;where#xff09;…DQL学习Data Query Language数据查询语言
DQL-语法 select 字段列表 from 表名列表 where 条件列表 group by 分组字段列表 having 分组后条件别表 order by 排序字段列表 limit 分页参数 基本查询条件查询where聚合函数count、max、min、avg、sum分组查询group by排序查询order by分页查询limit
1基本查询
查询多个字段 select 字段1字段2字段3...from 表名;select * from 表名; 设置别名 select 字段1 [as 别名1],字段2[as 别名2]字段3[as 别名3]...from 表名; select 字段1[别名1]字段2[别名2]字段3[别名3]... from 表名; 去除重复记录 select distinct 字段列表 from 表名; 转义 select * from 表明 where name like /_张三 escape /; /之后的_不作为通配符 2条件查询 语法 select 字段列表 from 表名 where 条件列表; 条件
比较运算符功能大于大于等于小于小于等于等于或 !不等于between…and…在某个范围内含最小最大值in(…)在in之后的列表中的值多选一like 占位符模糊匹配_匹配单个字符%匹配任意个字符is null是null
逻辑运算符功能and 或 并且多个条件同时成立or 或 ‘//’或者多个条件任意一个成立not 或 非不是
例子 1、年龄等于30 select * from employee where age 30; 2、年龄小于30 select * from employee where age 30; 3、小于等于 select * from employee where age 30; 4、没有身份证 select * from employee where idcard; select * from employee where idcard is not null; 5、不等于 select * from employee where age ! 30; 6、年龄在20到30之间 select * from employee where age between 20 and 30; select * from employee where age 20 and age 30; 7、下面语句不报错但查不到任何信息 select * from employee where age between 30 and 20; 8、性别为女且年龄小于30 select * from employee where age 30 and gender 女; 9、年龄等于25或30或35 select * from employee where age 25 or age 30 or age 35; select * from employee where age in (25, 30, 35); 10、姓名为两个字 select * from employee where name like __; 11、身份证最后为X select * from employee where idcard like %X; 3聚合查询聚合函数 常见聚合函数
函数功能count统计数量max最大值min最小值avg平均值sum求和
语法 select 聚合函数字段列表from 表名; 例子 select countidfrom employee where workaddress 广东省;