[英]MySQL group by date and convert from unix timestamp
I have the following sql table (simplified) 我有以下sql表(简化)
ID (int) title (text) date (int)
--------------------------------------------
1 Hello World 1378148920
2 Hello World2 1378182183
3 Hello World3 1378129838
4 Hello World4 1378146160
5 Hello World5 1378138038
....
The table has thousands of entries. 该表有数千个条目。
I wan't to ask you if it is possible to build a SQL query that groups all the posts by date but only as day. 我不想问你是否有可能构建一个SQL查询,按日期对所有帖子进行分组,但仅作为日期。
So at the end I wan't to build a graph like this (for the last 5 days): 所以最后我不想建立这样的图形(过去5天):
02.09.2013: 13 posts
01.09.2013: 14 posts
NOTE: the timestamp aren't real (they are all from today) 注意:时间戳不是真实的(它们都来自今天)
You can use from-unixtime() 你可以使用from-unixtime()
select FROM_UNIXTIME(`date`, '%d.%m.%Y') as ndate,
count(id) as post_count
from your_table
group by ndate
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.