• 2024年5月12日下午2点26分 chord202024-05-1224-05-12#!!#data2024年5月12日下午2点30分 #test

test

com+p:命令行 com+o:快速切换

git testy test

大标题1

  • 一级标题用#后跟空格
  • 二级标题用##后跟空格发
  • 条理性显示用-
  • 学习obsidian |起正名
  • 有序列表:(1. )
  • 学习精准双链
    Transclude of Welcome#^6addca
    link
  1. aaa
  2. bbb
  3. ccc

中标题

Tap键无序再分级
  • 小面这句话很重要
    • 这句话很重要
      • 使用方法两边加**

小标题

  • 斜体用*
  • 优雅
  • 像上面一样

这是一条引用 引用:>

小小标题
  • 删除线用~
  • 删除我哈哈
  • 像上面一样 我想换行 你呢
    得到 方式付款

顶顶顶

分隔线用“--- ” 这是b站主页( ” [] () ” )

  • ctrl+L
create table emp(
id int comment '姓名' ,
workon varchar(10) comment  '工号',
name varchar(10) comment '姓名',
gender char(1) comment '性别',
age tinyint unsigned comment '年龄',
idcard char(18) comment '身份证号',
entrydata date comment '入职时间'
) comment '员工表';
 
alter table emp add nickname varchar(20) comment '昵称';
 
alter table emp change nickname username varchar(30) comment '用户名';
 
alter table emp drop username;
 
alter table emp rename to employee;
 
insert into employee(id, workon, name, gender, age, idcard, entrydata)  values (1,'1','itcast','男',10,'13042920020828030','2002-08-28');
 
select * from employee;
 
insert into employee value (2,'2','itcast2','女',18,'13042920021000332','2002-10-05');
 -- 批量添加员工信息
insert into employee value (3,'2','李梦圆','女',18,'13042920021000332','2002-10-05'),(4,'2','段鑫','男',18,'13042920021000332','2002-10-05');
 
 
update employee set idcard = '130429200208280333',name = '向晚' where idcard = '3042920020828030';
update employee set id = 2 where name = '小赵';
 
 --
update employee set name = 'ithema' where id = 1;
 -- 把所有id 为1的员工名字变为小赵性别变为女
update employee set name = '小赵',gender = '女' where id = 1;
 -- 将所有员工更改入职时间
update employee set entrydata = '2008-8-28';
 -- 删除id 为2 的员工
delete from employee where id = 2;
 -- 删除所有员工
delete from employee ;
 
 
insert into emp (id, workon, name, gender, age, idcard, workaddress, entrydata)
value (1,'1','刘1','女','20','130429200208281232','北京','2002-03-23'),
      (2,'2','刘2','男','24','130429200208285333','上海','2003-10-21'),
      (3,'3','刘3','女','27','130429200208281535','北京','2003-03-25'),
      (4,'4','刘4','男','30','130429200208281257','成都','2004-01-12'),
      (5,'5','刘5','女','14','130429200208281254','唐山','2009-12-14'),
      (6,'6','刘6','男','16','130429200208281234','东北','2008-11-27'),
      (7,'7','刘7','女','23','130429200208281233','桂林','2008-09-29'),
      (8,'8','刘8','女','20','130429200208281231','北京','2007-04-01'),
      (9,'9','刘9','男','29','1304292002082812313','山东','2008-09-01'),
      (10,'10','刘10','女','10','130429200208284634','北京','2007-01-24'),
      (11,'11','刘11','女','15','130429200208281267','河南','2007-02-27'),
      (12,'12','刘12','男','20','130429200208281215','北京','2006-04-28'),
      (13,'13','刘13','女','21','130429200208281267','河北','2005-01-23'),
      (14,'14','刘14','男','22','130429200208281286','兰州','2002-04-05'),
      (15,'15','刘15','女','29','130429200208281245','北京','2001-05-01'),
      (16,'16','刘16','男','23',null,'西北','2004-01-05');
 
 -- 查询指定字段
 select name,workon,age from emp;
 
 -- 查询返回所有字段
 select id, workon, name, gender, age, idcard, workaddress, entrydata from emp;
 select * from emp;
 
 -- 查询所有员工的工作地址,起别名
 select workaddress as '工作地址' from emp;
 select workaddress '工作地址' from emp;
 
 -- 查询员工上班地址(不要重复
 select distinct workaddress '工作地点' from emp;
 
 -- 条件查询
 -- 1.查询年领等于24的员工    (!=
 select * from emp where age = 24;
 -- 2.查询年龄小于20的员工信息
 select * from emp where age < 20;
 -- 3.查询没有身份证信息的员工 (is not
 select * from emp where idcard is null;
 -- 4.查询年龄在15-20岁之间的员工(包括)
 select * from emp where age >= 15 && age <=20;
 select * from emp where age >= 15 and age <=20;
 select * from emp where age between 15 and 20;
 -- 5.查询性别为女且年龄小于22的员工
 select * from emp where gender = '女' and age <= 22;
 -- 6.查询年龄等于18或20或27的员工
 select * from emp where age = 18 or age = 10 or age = 27;
 select * from emp where age in (18,10,27);
 -- 7.查询姓名为两个字的员工信息
 select * from emp where name like '___';
 -- 8.查询地址为京的员工信息
 select * from emp where workaddress like '%京';
 
-- 聚合函数
 -- 1.统计该企业的员工数量
 select count(*) from emp;
 
 -- 2.统计该企业的平均年龄
 select avg(age) from emp;
 
 -- 3.统计该企业员工的最大年龄
 select max(age) from emp;
 
 -- 4.求北京地区的员工年龄之和
 
 select sum(age) from emp where workaddress = '北京';
 
 -- 分组查询
 -- 根据性别分组,统计男性员工和女性员工的数量
 select gender,count(*) from emp group by gender;
 -- 根据性别分组,统计男性员工和女性员工的平均年龄
 select gender,avg(age) from emp group by gender;
 -- 查询年龄大于18岁的员工,并根据工作地址分组,获取员工数量大于等于2的工作地址
 select workaddress, count(*) from emp where age > 18 group by workaddress having count(*) >=3;
 
 
 -- 排序查询
 -- 1.根据年龄对公司员工升降序
 select * from emp order by age asc;
 select * from emp order by age desc;
 -- 2.根据年龄对公司员工升序排序,年龄相同,再根据入职时间进行降序排序
 select * from emp order by age asc, entrydata desc;
 
 -- 分页查询
 -- 1.查询第一页的员工数据,每页展示10条信息
 select * from emp limit 0,10;
 -- 1.查询第二页的员工数据,每页展示10条信息------>(页码数-1)*页展示记录数
 select * from emp limit 10,10;
 
 -- 综合
 select * from emp where gender = '男' and age<=40 and age >= 20 and name like '___';
 
 select gender,count(*) from emp where age <= 25 group by gender;
 
 select name , age from emp where age <= 23 order by age asc ,entrydata desc;
 
 select * from emp where gender = '男' and age between 19 and 24 order by age asc,entrydata asc limit 5;