计数(月底不同
我有一个数据库,其中包含 TSTAMP USERNAME SUBCR_TYPE 和 BALANCE 的日志。 我想知道有多少用户在过去的每个月底都有 SUBSCR_TYPE 的正余额
结果表应该如下所示
silver|gold|platinum
2011-09 34|56 |109
2011-10 23|43 |67
2011-11 33|56 |45
.
.
.
我已经尝试过,结果明显错误,
SET @ts = unix_timestamp(LAST_DAY('2011-09-01'));
SELECT COUNT(DISTINCT USERNAME) AS 'silver'
FROM accLog_table
WHERE BALANCE>=1
AND SUBSCR_TYPE = 'silver'
AND TSTAMP<@ts
我该如何正确执行此操作?
I have a db with logs of TSTAMP USERNAME SUBCR_TYPE and BALANCE.
I want to know how many users had at each past end of month a positive BALANCE by SUBSCR_TYPE
The resulting table should look like this
silver|gold|platinum
2011-09 34|56 |109
2011-10 23|43 |67
2011-11 33|56 |45
.
.
.
I have tried this with obviously wrong results
SET @ts = unix_timestamp(LAST_DAY('2011-09-01'));
SELECT COUNT(DISTINCT USERNAME) AS 'silver'
FROM accLog_table
WHERE BALANCE>=1
AND SUBSCR_TYPE = 'silver'
AND TSTAMP<@ts
how can I do this correctly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我很高兴发布对我有用的解决方案
I happy to post a solution that worked for me