zoukankan      html  css  js  c++  java
  • sql统计公司最高薪酬和薪酬分布

    统计薪酬最高的和薪酬分布情况,下面包括表的创建和sql语句:

    CREATE TABLE `employee` (
      `id` int(4) DEFAULT NULL,
      `name` varchar(12) DEFAULT NULL,
      `salary` varchar(11) DEFAULT NULL,
      `iod` int(4) DEFAULT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8

    添加相应数据后得到表employee为:

    查询最高薪酬:

    SELECT office.`name` as office,
                 employee.`name` as name,
                 employee.salary
    from office,employee
    where employee.iod=office.iod
    and employee.salary=(SELECT MAX(salary) from employee  WHERE employee.iod=office.iod);
    #没有分组,避免了多人具有相同最高工资只显示一人的情况

    得到结果为:

    查看薪酬分组和百分比情况:

    select 
    (case when salary<3000  then '小于3000'
              when salary>=3000 and salary<5000 then '大于等于3000小于5000'
                else  '大于等于5000' end) as levels,
    count(salary) as Count,
    concat(convert(count(salary)*100/(select count(id) from employee),decimal(4,1)),'%') as persentage
    from employee GROUP BY levels ;
    
    #concat--连接字符串
    #convert--参数分别可以表示( 要转换到的类型, 合法的表达式, 格式化类型)
    #decimal(a,b)  a--代表精度   b--代表小数点位数

    结果如图:

  • 相关阅读:
    csp2020游记
    agc006_f Blackout
    CF1368G Shifting Dominoes
    AtCoder Grand Contest 009 简要题解
    Codeforces Round #666 (Div. 1)
    CSP 2019 树的重心
    Luogu-P4859 已经没什么好害怕的了
    2020.9.17 校内测试
    CF379F New Year Tree
    图论(小结论)
  • 原文地址:https://www.cnblogs.com/qianshuixianyu/p/9478549.html
Copyright © 2011-2022 走看看