• Mysql案例6_求平均薪资的等级最低的部门的部门名称


    背景:当前数据库的department表、salgrade表、employee表,数据分别如下:

    SQL语句:

    SELECT 
                t.*,s.grade
    FROM 
                (
                        SELECT 
                                e.departmentid, d.`name`,AVG(salary) avgsal
                        FROM 
                                employee e
                        INNER JOIN
                                department d
                        on 
                                e.departmentid=d.id
                        GROUP BY 
                                e.departmentid,d.`name`  ) t
    INNER JOIN
                salgrade s 
    ON
                t.avgsal BETWEEN s.losal AND s.hisal
    WHERE
                grade = (SELECT 
                                   MIN(t.grade) mingra
                          FROM (
                                                    SELECT 
                                                        t.*,s.grade
                                                    FROM 
                                                            (
                                                                        SELECT 
                                                                                e.departmentid, d.`name`,AVG(salary) avgsal
                                                                        FROM 
                                                                                employee e
                                                                        INNER JOIN
                                                                                department d
                                                                        on 
                                                                                e.departmentid=d.id
                                                                        GROUP BY 
                                                                                e.departmentid,d.`name`) t
                                                        INNER JOIN
                                                                salgrade s
                                                        ON
                                                                t.avgsal BETWEEN s.losal AND s.hisal) t
                                                    )
  • 相关阅读:
    jqGrid基本使用
    模块熟悉
    正则表达式-精髓
    登录+购物车+信息保存
    输入打开文件
    python打印目录下的文件名
    进度条
    模块导入
    正则表达式
    函数笔记
  • 原文地址:https://www.cnblogs.com/wodexk/p/10703865.html
Copyright © 2020-2023  润新知