我需要帮助。我有如下的MySQL表结构。 订单不是每日订单,而是总订单。日期是时间戳 我想查看最近3天按类别划分的销售趋势。我想找到他们类别中的哪些产品趋势
id, product_id, cat_id, orders, date
5, 2345, 15, 120, 2018-06-18 00:00:00
6, 2345, 15, 123, 2018-06-19 00:00:00
1, 2345, 15, 137, 2018-06-22 00:00:00
2, 2345, 15, 140, 2018-06-23 00:00:00
7, 456, 55, 127, 2018-06-18 00:00:00
8, 456, 55, 136, 2018-06-19 00:00:00
3, 456, 55, 152, 2018-06-22 00:00:00
4, 456, 55, 176, 2018-06-23 00:00:00
谢谢
答案 0 :(得分:0)
答案 1 :(得分:0)
我解决了这个问题。谢谢
select a.product_id,a.cox-b.az sales from (
SELECT product_id,
max(orders) AS cox
FROM
products
WHERE
date > ( CURDATE() - INTERVAL 3 DAY ) group by product_id order by cox desc) a,
(SELECT product_id,
orders AS az
FROM
products
WHERE
date > ( CURDATE() - INTERVAL 3 DAY ) group by product_id) b
where a.product_id=b.product_id
group by a.product_id order by sales desc