• MySQL习题


    /*SELECT
    `产品号码`,
    `产品名称`,
    `产品单价`
    FROM
    `产品信息`
    WHERE `产品单价`>(
    SELECT AVG(产品单价) FROM `产品信息`);*/

    /* SELECT
    `产品号码`,
    `产品名称`,
    `产品单价`,
    (SELECT AVG(产品单价) FROM `产品信息`) AS `产品单价`
    FROM
    `产品信息`
    WHERE `产品单价`>(
    SELECT AVG(`产品单价`) FROM `产品信息`)*/

    /*SELECT
    A.`产品号码`,
    A.`产品名称`,
    A.`产品单价`
    FROM `产品信息` AS A
    WHERE `供应商号码` IN (
    SELECT `供应商号码`
    FROM `供应商信息`
    WHERE `城市`='珠海市')*/

    /*SELECT
    SUM(A.`购买数量`) as total_sales,
    `产品号码`
    FROM
    `订单明细`AS A
    WHERE
    `订单号码` IN (
    SELECT `订单号码` FROM `订单信息` WHERE `订单日期`>'2018-01-01')
    GROUP BY
    `产品号码`
    ORDER BY `total_sales` DESC
    LIMIT 8*/

    /*SELECT
    A.`产品号码`,
    A.`产品名称`,
    B.`总销售额`
    FROM
    `产品信息` AS A
    LEFT JOIN # 临表子查询
    (
    SELECT
    `产品号码`,
    SUM(`购买数量`*`产品单价`) AS `总销售额`
    FROM `订单明细`
    GROUP BY `产品号码`
    )AS B
    ON B.`产品号码` = A.`产品号码`; */

    /*SELECT
    `产品号码`,
    `产品名称`,
    `供应商号码`,
    `产品单价`,
    `产品描述`,
    CASE
    WHEN `产品单价`<(SELECT AVG(`产品单价`) FROM `产品信息`) THEN '1'
    WHEN `产品单价`>=(SELECT AVG(`产品单价`) FROM `产品信息`)*2 THEN'3'
    ELSE 2
    END AS `售价级别`
    FROM `产品信息`;*/

    /*SELECT
    count(*),
    CASE
    WHEN year(订单日期)='2016' THEN '2016'
    WHEN year(订单日期)='2017' THEN '2017'
    ELSE '2018'
    END AS `年份`,
    CASE
    WHEN month(订单日期)<'4' THEN '第一季度'
    WHEN month(订单日期)<'7' THEN '第二季度'
    WHEN month(订单日期)<'10' THEN '第三季度'
    ELSE '第四季度'
    END AS '季度'
    FROM
    `订单信息`
    GROUP BY`年份`,`季度`*/

  • 相关阅读:
    linux下解压命令大全
    位运算的技巧
    逆元
    asp.net core 教程(五)
    day7--面向对象进阶(内含反射和item系列)
    day6--面向对象初识
    day6--二分查找法
    day6--递归函数
    day5--装饰器函数的信息打印,迭代器,生成器,列表推导式,内置函数
    python零散补充与总结
  • 原文地址:https://www.cnblogs.com/Grayling/p/11182818.html
Copyright © 2020-2023  润新知