项目描述
上传时间
浏览人数
-- 查询数据(查询所有的ID和name)
select id from employee;
-- 全查询
select * from employee;
-- 根据id查询
select * from employee where id = 92;
-- 根据性别查询
select * from employee where gender = '男';
-- 查已婚男性
select * from employee where gender = '男' and is_married = 1;
-- 查年龄在20-25区间的员工
select * from employee where age >= 20 and age <=25;
select * from employee where age between 20 and 25;
-- 查20-25这个区间的男性员工
select * from employee where age >= 20 and age <=25 and gender = '男';
-- 查男性员工的人数
select count(id) from employee where gender = '男';
# 拼接和递增、递减...
update employee set name = concat(name, '的') where id = 89;
# 模糊查询
select name from employee where name like '%英%';
# 排序
select * from employee order by salary; # 从小到大
select * from employee order by salary desc; # 从大到小
select * from employee where name like '%王%' order by age;
# 找最大/找最小
select max(age) from employee;
select min(age) from employee;
# 查找年龄最大的员工信息 子查询
select * from employee where age = (select max(age) from employee);
# 查找平均薪资
select avg(salary) from employee;
select sum(salary) from employee;
# 分组统计
select gender, count(id) from employee group by gender;
# limit 分页alter
select * from employee limit 10, 5; # 索引 条数