如何计算特定月份每天的订阅数

gpnt7bae  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(278)

(使用mysql)我需要知道一个月每天有多少人订阅。这是我目前的疑问:

SELECT COUNT(user_ID) AS Subs,  DATE(subscription_date) AS Day_Joined FROM Users GROUP BY DAY(Day_Joined), user_ID HAVING MONTH(Day_Joined) = 03 ORDER BY Day_Joined

我希望输出能给我:

subs Day_Joined
- 10   2018-03-04
- 20   2018-03-05
- 30   2018-03-06

到目前为止,它给了我:

subs Day_Joined
- 5   2018-03-04
- 3   2018-03-04
- 2   2018-03-04
... and so on..
hgqdbh6s

hgqdbh6s1#

你应该只在你加入的那一天分组

SELECT COUNT(user_ID) AS Subs
       , DATE(subscription_date) AS Day_Joined
  FROM Users
  GROUP BY DATE(subscription_date)
  HAVING MONTH(DATE(subscription_date)) = 03
  ORDER BY

如果您也按user\u id分组,则没有distinct user\u id的计数。。

相关问题