Mysql 如何从正在运行的总销售额中检索每日销售额
我需要帮助。我有如下MySQL表结构。 订单不是每日订单,而是总订单。日期是时间戳 我想看看过去3天的销售趋势。我想找出他们类别中的哪个产品趋势Mysql 如何从正在运行的总销售额中检索每日销售额,mysql,sql,Mysql,Sql,我需要帮助。我有如下MySQL表结构。 订单不是每日订单,而是总订单。日期是时间戳 我想看看过去3天的销售趋势。我想找出他们类别中的哪个产品趋势 id、产品id、类别id、订单、日期 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, 2
id、产品id、类别id、订单、日期
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
谢谢您需要按日期进行铸造,按产品id和类别id进行分组,并根据我假设的“趋势”一词按订单总数降序排列:
select product_id, cat_id, count(orders) as total_orders
from mytable
where cast(date as date) >= cast(sysdate()-3 as date)
group by product_id, cat_id
order by count(orders) desc;
product_id cat_id total_orders
2345 15 1
456 55 1
我解决了这个问题。谢谢
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
请参见编辑问题并显示所需结果。这意味着什么:“我想找到他们类别中的哪个产品趋势”?谢谢Barbaros bey。Buraya yazdiktan sonra kafam calismaya basladi。霍尔·埃蒂姆。@TariyelValiyev Birşey değil değerli dostum kolay gelsin:)