接下来,开始编辑语句
from_unixtime函数支持转换时间戳为字符串,我们把时间戳转换为日期
from_unixtime( create_time, '%y年%m月%d日' )
然后,根据这个日期分组就可以了,下面是完整的sql语句
select from_unixtime( create_time, '%y年%m月%d日' ) as day,count(*) as count,sum(score) as score from t_everygames where user_id =$userid group by from_unixtime( create_time, '%y年%m月%d日' ) order by 1 limit 0,6
同理,还可以按照年、月、日、时、分来分组,是不是很方便呢?
如果数据库中存的是字符串,例如2018-1-30这种,用到则是date_format()这个函数。
相关推荐:
mysql中索引与from_unixtime的问题详解
索引和from_unixtime在mysql中问题详解
from_unixtime 格式化mysql时间戳函数
以上就是mysql中的from_unixtime实现按天查询的详细内容。