SELECT `month`, `num_month` / `num_year` * 100 AS "percent"
FROM (SELECT MONTH(`dateOfOrder`) AS "month", COUNT(*) AS num_month
FROM `order`
WHERE YEAR(`dateOfOrder`) = 2018
GROUP BY MONTH(`dateOfOrder`) a
CROSS JOIN (SELECT COUNT(*) AS num_year
FROM `order`
WHERE YEAR(`dateOfOrder`) = 2018) b
1条答案
按热度按时间ki1q1bka1#
我会交叉连接两个查询。第一个是每月销售产品数量的总和,第二个是当年销售产品总数的总和: