网站上做网页怎么改图片,网站开发公司需要哪些资质,哪家云盘免费空间大,杭州最新消息今天SQL中的DQL和DCL DQL基本查询条件查询聚合函数分组查询排序查询分页查询 DCL管理用户权限控制 学习黑马MySQL课程#xff0c;记录笔记#xff0c;用于复习。 DQL
DQL英文全称是Data Query Language(数据查询语言)#xff0c;数据查询语言#xff0c;用来查询数据库中表的记… SQL中的DQL和DCL DQL基本查询条件查询聚合函数分组查询排序查询分页查询 DCL管理用户权限控制 学习黑马MySQL课程记录笔记用于复习。 DQL
DQL英文全称是Data Query Language(数据查询语言)数据查询语言用来查询数据库中表的记录。
基本查询
#1.查询多个字段
select 字段1, 字段2, 字段3 ... from 表名 ;
select * from 表名 ;
#2.字段设置别名
select 字段1 [ as 别名1 ] , 字段2 [ as 别名2 ] ... from 表名;
select 字段1 [ 别名1 ] , 字段2 [ 别名2 ] ... from 表名;
#去重
select distinct 字段列表 from 表名;条件查询
select 字段列表 from 表名 where 条件列表;条件列表(除大于小于)
比较运算符功能 或 !不等于between … and …在某个范围之内in()in后列表内任一值like 占位符_单个字符 % 任意字符is null为空
#查询姓名为两个字的员工信息
select * from emp where name like __;
#查询身份证号最后一位是X的员工信息
select * from emp where idcard like %X;聚合函数
将一列数据作为一个整体进行纵向计算 常见的聚合函数null值不参与计算
count统计数量max最大值min最小值avg平均值sum求和
select 聚合函数(字段列表) from 表名;
select count(*) from emp; -- 统计总记录数
select count(idcard) from emp; -- 统计idcard字段不为null的记录数分组查询
select 字段列表 from 表名 [ where 条件 ] group by 分组字段名 [having 分组后过滤条件];where与having区别
执行时机不同where是分组之前进行过滤不满足where条件不参与分组having是分组之后对结果进行过滤。判断条件不同where不能对聚合函数进行判断having可以。 注意事项: • 分组之后查询的字段一般为聚合函数和分组字段查询其他字段无任何意义。 • 执行顺序: where 聚合函数 having 。 • 支持多字段分组, 具体语法为 : group by columnA,columnB
#根据性别分组 , 统计男性员工 和 女性员工的数量
select gender, count(*) from emp group by gender ;
#查询年龄小于45的员工, 并根据工作地址分组 , 获取员工数量大于等于3的工作地址
#1.查询年龄小于45的员工数量
select count(*) from emp where age 45;
#2.根据工作地址分组,并把count(*)起别名address_count
select workaddress,count(*) address_count from emp where age 45 group by workaddress;
#3.获取员工数量大于等于3的工作地址
select workaddress,count(*) address_count from emp where age 45 group by workaddress having address_count 3;排序查询
#多字段排序当第一个字段值相同时才会根据第二个字段进行排序 ;
select 字段列表 from 表名 order by 字段1 排序方式1 , 字段2 排序方式2 ;排序方式
ASC升序默认值DESC降序
select * from emp order by age asc , entrydate desc;分页查询
select 字段列表 from 表名 limit 起始索引, 查询记录数 ;起始索引从0开始起始索引 查询页码 - 1* 每页显示记录数。如果查询的是第一页数据起始索引可以省略直接简写为 limit 10。
#查询第1页员工数据, 每页展示10条记录
select * from emp limit 10;
#查询第2页员工数据, 每页展示10条记录 ----- (页码-1)*页展示记录数(2-1)*1010
select * from emp limit 10,10;#查询所有年龄小于等于35岁员工的姓名和年龄并对查询结果按年龄升序排序如果年龄相同按入职时间降序排序。
select name , age from emp where age 35 order by age asc , entrydate desc;
#查询性别为男且年龄在20-40 岁(含)以内的前5个员工信息对查询的结果按年龄升序排序年龄相同按入职时间升序排序
#1.查询性别为男且年龄在20-40 岁(含)以内的员工
select * from emp where gender 男 and age between 20 and 40
#2.对查询的结果按年龄升序排序年龄相同按入职时间升序排序前5个员工信息
select * from emp where gender 男 and age between 20 and 40 order by age asc, entrydate asclimit 5;执行顺序 表–条件–分组–返回字段–排序–分页
DCL
DCL英文全称是Data Control Language(数据控制语言)用来管理数据库用户、控制数据库的访问权限。
管理用户
#查询用户
select * from mysql.user;Host代表当前用户访问的主机, 如果为localhost, 仅代表只能够在当前本机访问是不可以远程访问的。 User代表的是访问该数据库的用户名。在MySQL中需要通过Host和User来唯一标识一个用户。
#创建用户
create user 用户名主机名 identified by 密码;
create user sxl% identified by 123456;
#修改用户密码
alter user 用户名主机名 identified with mysql_native_password BY 新密码 ;
#删除用户
drop user 用户名主机名 ;权限控制
权限说明all所有权限select查询数据insert插入数据update修改数据delete删除数据alter修改表drop删除数据库/表/视图create创建数据库/表
#查询权限
show grants for 用户名主机名 ;
#授予权限
grant 权限列表 on 数据库名.表名 to 用户名主机名;
grant all on test.* to sxl%;
#撤销权限
reveke 权限列表 on 数据库名.表名 from 用户名主机名;
文章转载自: http://www.morning.knczz.cn.gov.cn.knczz.cn http://www.morning.tqgmd.cn.gov.cn.tqgmd.cn http://www.morning.fbylq.cn.gov.cn.fbylq.cn http://www.morning.znrgq.cn.gov.cn.znrgq.cn http://www.morning.ttvtv.cn.gov.cn.ttvtv.cn http://www.morning.c7491.cn.gov.cn.c7491.cn http://www.morning.wctqc.cn.gov.cn.wctqc.cn http://www.morning.kczkq.cn.gov.cn.kczkq.cn http://www.morning.fpxsd.cn.gov.cn.fpxsd.cn http://www.morning.hlnys.cn.gov.cn.hlnys.cn http://www.morning.syznh.cn.gov.cn.syznh.cn http://www.morning.ishoufeipin.cn.gov.cn.ishoufeipin.cn http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn http://www.morning.rxnxl.cn.gov.cn.rxnxl.cn http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.zzgkk.cn.gov.cn.zzgkk.cn http://www.morning.xphcg.cn.gov.cn.xphcg.cn http://www.morning.xtdtt.cn.gov.cn.xtdtt.cn http://www.morning.hrpmt.cn.gov.cn.hrpmt.cn http://www.morning.wjhqd.cn.gov.cn.wjhqd.cn http://www.morning.ccyjt.cn.gov.cn.ccyjt.cn http://www.morning.plfy.cn.gov.cn.plfy.cn http://www.morning.gwyml.cn.gov.cn.gwyml.cn http://www.morning.mtxrq.cn.gov.cn.mtxrq.cn http://www.morning.gnkbf.cn.gov.cn.gnkbf.cn http://www.morning.kyytt.cn.gov.cn.kyytt.cn http://www.morning.qjxkx.cn.gov.cn.qjxkx.cn http://www.morning.yxwrr.cn.gov.cn.yxwrr.cn http://www.morning.rlbfp.cn.gov.cn.rlbfp.cn http://www.morning.xjtnp.cn.gov.cn.xjtnp.cn http://www.morning.rqnhf.cn.gov.cn.rqnhf.cn http://www.morning.dnhdp.cn.gov.cn.dnhdp.cn http://www.morning.rjrz.cn.gov.cn.rjrz.cn http://www.morning.ckhry.cn.gov.cn.ckhry.cn http://www.morning.sbyhj.cn.gov.cn.sbyhj.cn http://www.morning.bfjtp.cn.gov.cn.bfjtp.cn http://www.morning.nxhjg.cn.gov.cn.nxhjg.cn http://www.morning.stfdh.cn.gov.cn.stfdh.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.qbrs.cn.gov.cn.qbrs.cn http://www.morning.c7627.cn.gov.cn.c7627.cn http://www.morning.fhtbk.cn.gov.cn.fhtbk.cn http://www.morning.lkbyq.cn.gov.cn.lkbyq.cn http://www.morning.roymf.cn.gov.cn.roymf.cn http://www.morning.nshhf.cn.gov.cn.nshhf.cn http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.wypyl.cn.gov.cn.wypyl.cn http://www.morning.jppdk.cn.gov.cn.jppdk.cn http://www.morning.dwmtk.cn.gov.cn.dwmtk.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.jfcbz.cn.gov.cn.jfcbz.cn http://www.morning.rsnn.cn.gov.cn.rsnn.cn http://www.morning.gygfx.cn.gov.cn.gygfx.cn http://www.morning.wktbz.cn.gov.cn.wktbz.cn http://www.morning.tklqs.cn.gov.cn.tklqs.cn http://www.morning.cgtrz.cn.gov.cn.cgtrz.cn http://www.morning.zqsnj.cn.gov.cn.zqsnj.cn http://www.morning.kxbdm.cn.gov.cn.kxbdm.cn http://www.morning.pwbps.cn.gov.cn.pwbps.cn http://www.morning.bwjws.cn.gov.cn.bwjws.cn http://www.morning.bpmfz.cn.gov.cn.bpmfz.cn http://www.morning.hnrdtz.com.gov.cn.hnrdtz.com http://www.morning.qhczg.cn.gov.cn.qhczg.cn http://www.morning.zkgpg.cn.gov.cn.zkgpg.cn http://www.morning.rjyd.cn.gov.cn.rjyd.cn http://www.morning.qpsdq.cn.gov.cn.qpsdq.cn http://www.morning.rwfj.cn.gov.cn.rwfj.cn http://www.morning.bpkqd.cn.gov.cn.bpkqd.cn http://www.morning.fkyrk.cn.gov.cn.fkyrk.cn http://www.morning.tkzqw.cn.gov.cn.tkzqw.cn http://www.morning.sbpt.cn.gov.cn.sbpt.cn http://www.morning.jjxxm.cn.gov.cn.jjxxm.cn http://www.morning.fbpyd.cn.gov.cn.fbpyd.cn http://www.morning.zknxh.cn.gov.cn.zknxh.cn http://www.morning.mhsmj.cn.gov.cn.mhsmj.cn http://www.morning.ljygq.cn.gov.cn.ljygq.cn http://www.morning.nkqnn.cn.gov.cn.nkqnn.cn http://www.morning.psyrz.cn.gov.cn.psyrz.cn http://www.morning.tnjff.cn.gov.cn.tnjff.cn