我有两个查询来获取活动用户和非活动用户的计数。
查询1 (Count Active Users)
select COUNT(id) as qty,
Date(active_on) as active_on_date
from `activations`
where `store_id` = 2475
and `current_status` = 'active'
and `active_on` is not null
and (`active_on` between '2021-01-24 14:15:55' and '2021-02-16 14:15:55')
group by `active_on_date`
order by `active_on_date` asc
查询2 (Count Inactive Users)
select COUNT(id) as qty
from `activations`
where `store_id` = 2475
and `current_status` = 'inactive'
and `active_on` is null
and `proceed_on` is not null
and (`proceed_on` between '2021-01-24 14:15:55' and '2021-02-16 14:15:55') group by Date(proceed_on)
order by Date(proceed_on) asc
注意:proced_on和active_on是不同的日期列。我想要得到这样的结果:
已激活数量 | 未激活数量 | 日期 |
---|
SELECT SUM(current_status = 'active') AS qty_active,
SUM(current_status = 'unactive') AS qty_unactive,
DATE(active_on) AS active_on_date
FROM activations
WHERE store_id = 2475
AND active_on BETWEEN '2021-01-24 14:15:55' AND '2021-02-16 14:15:55'
GROUP BY active_on_date
ORDER BY active_on_date ASC
p。在按日期分组时,从中午开始计数是很奇怪的。这是什么神奇的时刻-14:15:55
?