/*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`年份`,`季度`*/