前述
mysql中date_add()函数的使用
题目描述
leetcode题目:1141. 查询近30天活跃用户数
Code
写法一
select activity_date as day, count(distinct user_id) as active_users
from Activity
where activity_date > '2019-06-27' and activity_date <= '2019-07-27'
group by activity_date
注意:where activity_date between '2019-06-27' and '2019-07-27'
ERROR: 不包含’2019-06-27’
写法二: date_add()
select activity_date as day, count(distinct user_id) as active_users
from Activity
where activity_date between date_add('2019-07-27', interval -29 day) and '2019-07-27'
group by activity_date
学习题解中的用date_add()函数:(新手)关于使用DATE_ADD简化“近30天”的思路