按X天的范围分组 [英] Group by a range of X days
本文介绍了按X天的范围分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一套或多个记录,并且我想对它们进行计数并将它们分组到一定范围内,例如,我想计算由X天组创建的记录
I have a set or records and I want to count and group them by a certain range e.g. I want to count the records that were created by groups of X days
e.g. SELECT COUNT(*) FROM `table` GROUP BY /*`created` 3 days/*
推荐答案
您可以执行类似以下操作:
SELECT COUNT(*)FROM表GROUP BY FLOOR(created / 3)
You can do something like
SELECT COUNT(*) FROM table GROUP BY FLOOR(created / 3)
...我想。
尽管
Although if created
is a date field, you'll have to do a little more jiggering to get it into a number value for this to work.
这篇关于按X天的范围分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文