MySQL group by date and convert from unix timestamp(MySQL 按日期分组并从 unix 时间戳转换)
本文介绍了MySQL 按日期分组并从 unix 时间戳转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有如下sql表(简体)
I have the following sql table (simplified)
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
....
该表有数千个条目.
我不想问你是否可以构建一个 SQL 查询,将所有帖子按日期分组,但仅按天分组.
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.
所以最后我不想构建这样的图表(过去 5 天):
So at the end I wan't to build a graph like this (for the last 5 days):
02.09.2013: 13 posts
01.09.2013: 14 posts
注意:时间戳不是真实的(它们都是从今天开始的)
NOTE: the timestamp aren't real (they are all from today)
推荐答案
你可以使用from-unixtime()
select FROM_UNIXTIME(`date`, '%d.%m.%Y') as ndate,
count(id) as post_count
from your_table
group by ndate
这篇关于MySQL 按日期分组并从 unix 时间戳转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:MySQL 按日期分组并从 unix 时间戳转换


基础教程推荐
猜你喜欢
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- 在多维数组中查找最大值 2021-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01