卧槽,好久没写博客了!试着学了下SQL~

凉了凉了!

燃某大喊上面这四个字,然而还是没有人鸟一下。

 

大概是这么一个题目

于是我:

第一题:

SELECT
    `department_name`,
    COUNT(*) AS 总人数
FROM
    `test1`
GROUP BY
    `department_name`

第二题:

SELECT
    `department_name`,
    `type`,
    AVG(`salary`) AS 平均工资
FROM
    `test1`
WHERE
    `type` LIKE "钳工"
GROUP BY
    `department_name`,`type`,`salary`

SELECT
    `department_name`,
    AVG(`salary`) AS 平均工资
FROM
    `test1`
WHERE
    `type` LIKE "钳工"
GROUP BY
    `department_name`

第三题:

SELECT
    `department_name`,
    `type`,
    AVG(`salary`) AS 平均工资
FROM
    `test1`
WHERE
    `type` = "钳工"
GROUP BY
    `department_name`,
    `type`
HAVING
    AVG(`salary`) > 2000

第四题:

SELECT
    a.`name`,
    a.`department_name`,
    a.`type`,
    a.`salary`
FROM
    `test1` a
WHERE
    `salary` <(
    SELECT
        AVG(`salary`)
    FROM
        `test1`
    WHERE
        a.`department_name` = `department_name` AND a.`type` = `type`
    GROUP BY
        `department_name`
)

怎么样!!!是不是很nb(蠢)?

我特么花了一下午,研究出来的!QAQ……

此贴终结。。。

好想成为码农啊……

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注

1 × 4 =