SQL使用unix时间戳计算一个月内的记录
我试图返回每个月内的记录数,并按月/年对结果进行分组。
架构看起来像这样:
id title timestamp
我一直在四处寻找,但无法得到我期望的结果。谢谢。
I'm trying to return the count of records within each month and group the result by month / year.
Schema looks something like this:
id title timestamp
I've been searching around but I can't get the result as I expect it. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
设置时间戳的格式,然后按其分组。
按月分组:
按年分组:
如果时间戳字段存储为 unixtime-value,只需将
FROM_UNIXTIME()
字段周围:Format the timestamp, then group by it.
Group by Month:
Group by Year:
If the timestamp-field is stored as a unixtime-value, just wrap
FROM_UNIXTIME()
around the field: