Unix 时间 & mysql
我的表上有一个名为 X 的字段,我存储 unixtime(php -> time())。 我的问题是:
如何列出数据库中的所有月份,例如:6.2009 8.2009 等..
我的第二个问题是:
如何进行查询以列出同一字段 X 上的月份和年份的所有信息(我存储 unixtime),我知道这不起作用,但也许您可以更好地理解它:where
日期
= '06.2009'
有解决方案吗?
I have a field on my table which is called X, and I store unixtime(php -> time()).
My question is:
How can I list all the months from my DB, something like: 6.2009 8.2009 etc..
And my second question is:
How can I make a query to list all the informations based on a month and year on the same field X(i store unixtime), I know this doesn't work, but mabe you can understand it better: where
date
= '06.2009'
Any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
列出所有月份:
返回给定年份和年份的所有行。 月份:
List all months:
Return all rows with a given year & month:
试试这个
SELECT FROM_UNIXTIME(X,'%m.%Y') FROM TABLE GROUP BY FROM_UNIXTIME(X,'%m.%Y')
SELECT * FROM TABLE WHERE FROM_UNIXTIME(X,'%m.%Y')='06.2009'
再见
Try this
SELECT FROM_UNIXTIME(X,'%m.%Y') FROM TABLE GROUP BY FROM_UNIXTIME(X,'%m.%Y')
SELECT * FROM TABLE WHERE FROM_UNIXTIME(X,'%m.%Y')='06.2009'
Bye
要回答你的第一个问题,你可以通过分组来做到这一点:
至于你的第二个问题,这取决于你想要做什么。 例如:
将返回每组的付款平均值和行数(总和)。
要获取特定时间范围内未分组的信息,请像这样减少查询:
To answer your first question, you would do this with grouping:
As for your second question, this depends on what you're trying to do. For example:
Would return the average of the payments and the number (sum) of rows for each group.
To get information ungrouped from a specific timeframe, reduce the query like so: