SQL获取范围内的用户
我有一个数据库,用于存储用户订阅和取消订阅服务的时间。我想做的是查看每个月有哪些人取消订阅,然后查看其中有多少人在订阅后 30 天内取消订阅。我有两个字段,DateJoined_
和 DateUnsub_
,它们都返回 smalldatetime
。我如何使用 DateJoined
和 DateUnsub
找到这些人?我知道我必须进行某种计算,如果我不使用 SQL,我可以轻松完成此操作 - 有什么建议吗?
I've got a database that stores when users subscribed and unsubscribed from a service. What I want to do is see who unsubscribed each month, and then see how many of those people had unsubscribed within 30 days of subscribing. I have two fields, DateJoined_
and DateUnsub_
that both return a smalldatetime
. How would I be able to find these people using DateJoined
and DateUnsub
? I know I have to do some sort of calculation, and I could do this easily if I wasn't using SQL - any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
http://msdn.microsoft.com/en-us/library/ms189794.aspx
http://msdn.microsoft.com/en-us/library/ms189794.aspx
您使用什么数据库管理系统?对于 MySQL:
What DBMS are you using? For MySQL:
至于获取每月取消订阅的用户数量,您可以
GROUP BY DATEPART(year, DateUnsub_)、DATEPART(month, DateUnsub_)
或限制这些日期部分来获取用户列表。http://msdn.microsoft.com/en-us/library/ms174420.aspx
As for getting the number of users who unsubscribed each month, you could
GROUP BY DATEPART(year, DateUnsub_), DATEPART(month, DateUnsub_)
or instead limit on those dateparts to get the list of users.http://msdn.microsoft.com/en-us/library/ms174420.aspx