91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql 子查詢高級經典例題

發布時間:2020-02-29 09:07:27 來源:網絡 閱讀:310 作者:wx5d21d5e6e5ab1 欄目:MySQL數據庫

查詢部門平均工資是最低部門的信息
法1:先找到平均工資和最低平均工資相等的部門編號,然后再作為篩選條件匹配部門表

SELECT d.*
FROM departments d
WHERE d.department_id=(
    SELECT department_id
    FROM employees
    GROUP BY department_id
    HAVING AVG(salary) =
    (
        SELECT MIN(a)
        FROM(
            SELECT AVG(salary) a,department_id
            FROM employees
            GROUP BY department_id
                 )b
    )
)

法2:通過排序然后LIMIT直接找到工資最低的部門標號,然后匹配部門表

SELECT d.*
FROM departments d
WHERE d.department_id=(
    SELECT department_id
    FROM employees
    GROUP BY department_id
    ORDER BY AVG(salary) ASC
    LIMIT 1
);

查詢平均工資最低的部門信息和該部門的平均工資
法:將department表和帶有最低平均工資的表連接起來,再查詢

SELECT d.*,a
FROM departments d
INNER JOIN(
    SELECT AVG(salary) a,department_id
    FROM employees
    GROUP BY department_id
    ORDER BY AVG(salary) ASC
    LIMIT 1
) b
ON d.department_id=b.department_id;

查詢平均工資最高的job信息

SELECT *
FROM jobs
WHERE jobs.`job_id`=(
    SELECT job_id
    FROM employees e
    GROUP BY e.job_id
    ORDER BY AVG(salary) DESC
    LIMIT 1
);

查詢平均工資高于公司平均工資的部門有些
法:查找平均工資高于公司平均工資的表,然后和部門表連接

    SELECT department_name
FROM departments d
INNER JOIN(
    SELECT AVG(salary),department_id
    FROM employees
    GROUP BY department_id
    HAVING AVG(salary)>(
        SELECT AVG(salary)
        FROM employees
    )
) a
WHERE d.department_id=a.department_id;

查詢出公司中所有manager的詳細信息在employees表中

SELECT *
FROM employees
WHERE employee_id IN(
    SELECT manager_id
    FROM employees
);

查詢各個部門中最高工資中的那個部門的最低工資是多少

SELECT MIN(e.salary)
FROM employees e
WHERE e.department_id=(
    SELECT department_id
    FROM employees
    GROUP BY department_id
    ORDER BY MAX(salary) DESC
    LIMIT 1
)

查詢平均工資最高的部門的manager的詳細信息:last_name,department_id,email,salary

SELECT e.last_name,e.department_id,e.email,e.salary
FROM employees e
INNER JOIN departments d
ON d.manager_id=e.employee_id
WHERE d.department_id=(
    SELECT department_id
    FROM employees
    GROUP BY department_id
    ORDER BY AVG(salary) DESC
    LIMIT 1
)
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

南岸区| 石台县| 宁蒗| 四会市| 故城县| 西宁市| 安康市| 门源| 卢湾区| 黔东| 万盛区| 洮南市| 阳山县| 呼和浩特市| 府谷县| 辉南县| 上蔡县| 昭平县| 崇信县| 外汇| 峨山| 遵化市| 集安市| 南通市| 建瓯市| 泰兴市| 隆化县| 宁武县| 洛川县| 安顺市| 庆云县| 洮南市| 裕民县| 剑河县| 大悟县| 托克逊县| 翁源县| 大庆市| 若羌县| 溆浦县| 平顶山市|