zoukankan      html  css  js  c++  java
  • mysql练习题3

    USE day44;
    
    -- 1 查出所有员工的名字,薪资,格式为
    --     <名字:egon>    <薪资:3000>
    SELECT '姓名:',name,'薪资:',salary from employee;
    
    -- 2 查出所有的岗位(去掉重复)
    select distinct(post) from employee;
    
    -- 3 查出所有员工名字,以及他们的年薪,年薪的字段名为annual_year
    SELECT name,salary*12 as annual_year from employee;
    
    
    
    
    -- 1. 查看岗位是teacher的员工姓名、年龄
    select name,age from employee where post='teacher';
    
    -- 2. 查看岗位是teacher且年龄大于30岁的员工姓名、年龄
    select name,age from employee where post='teacher' and age>30;
    
    -- 3. 查看岗位是teacher且薪资在9000-1000范围内的员工姓名、年龄、薪资
    select name,age,salary from employee 
     			where post='teacher' and salary BETWEEN 9000 and 10000;
    
    -- 4. 查看岗位描述不为NULL的员工信息
    select * from employee where not null;
    
    -- 5. 查看岗位是teacher且薪资是10000或9000或30000的员工姓名、年龄、薪资
    select * from employee where post='teacher' and salary in (10000,9000,30000);
    
    -- 6. 查看岗位是teacher且薪资不是10000或9000或30000的员工姓名、年龄、薪资
    select * from employee where post='teacher' and salary not in(10000,9000,30000);
    
    -- 7. 查看岗位是teacher且名字是jin开头的员工姓名、年薪
    select * from employee where name like 'jin%';
    
    
    
    -- 1. 查询岗位名以及岗位包含的所有员工名字
    select post,group_concat(name) from employee group by post;
    
    -- 2. 查询岗位名以及各岗位内包含的员工个数
    select post,count(id) from employee group by post;
    
    -- 3. 查询公司内男员工和女员工的个数
    select sex,count(id) from employee group by sex;
    
    -- 4. 查询岗位名以及各岗位的平均薪资
    select post,avg(salary) from employee group by post;
    
    -- 5. 查询岗位名以及各岗位的最高薪资
    select post,max(salary) from employee GROUP BY post;
    
    -- 6. 查询岗位名以及各岗位的最低薪资
    select post,min(salary) from employee GROUP BY post;
    
    -- 7. 查询男员工与男员工的平均薪资,女员工与女员工的平均薪资
    select sex,avg(salary) from employee group by sex;
    
    
    
    
    -- 1. 查询各岗位内包含的员工个数小于2的岗位名、岗位内包含员工名字、个数
    select post,group_concat(name),count(id) from employee group by post having count(id)<2;
    
    -- 3. 查询各岗位平均薪资大于10000的岗位名、平均工资
    select post,avg(salary) from employee group by post having avg(salary)>10000;
    
    -- 4. 查询各岗位平均薪资大于10000且小于20000的岗位名、平均工资
    SELECT post,avg(salary) from employee group by post 
    				having avg(salary)>10000 and avg(salary)<20000;
    
    
    
    -- 1. 查询所有员工信息,先按照age升序排序,如果age相同则按照hire_date降序排序
    select * from employee order by age asc,hire_date desc;
    
    -- 2. 查询各岗位平均薪资大于10000的岗位名、平均工资,结果按平均薪资升序排列
    select post,avg(salary)as a from employee group by post 
    				having avg(salary)>10000 order by a asc;
    
    -- 3. 查询各岗位平均薪资大于10000的岗位名、平均工资,结果按平均薪资降序排列
    select post,avg(salary) a from employee group by post 
    						having avg(salary) >10000 order by a desc;
    
    
    
    
    -- 查看所有员工中名字是jin开头,n或者g结果的员工信息
    select * from employee where name REGEXP '^jin.*[n|g]$'; 
    
     
    
  • 相关阅读:
    ASP.NET Web API 2 之文件下载
    Windows 查看某个端口号是否被占用
    C# 数据类型之 String(字符串)
    数据表对应关系(一对一、一对多、多对多)
    嫁给程序员的好处,你get到了吗?
    ASP.NET Web API 2 之 HttpRequestMessage 对象
    C# 使用 log4net 记录日志
    Chrome 浏览器快捷键
    C# 获取程序运行时路径
    SpringBoot整合Pagehelper分页插件
  • 原文地址:https://www.cnblogs.com/fangjie0410/p/7732898.html
Copyright © 2011-2022 走看看