gpt4 book ai didi

mysql - SQL 中的不同时间

转载 作者:行者123 更新时间:2023-11-29 05:22:27 25 4
gpt4 key购买 nike

我的表有这个字段:

  `processeddate` int(14) DEFAULT NULL,

由 strtotime 转换的日期时间。内容类似于1401847266

我如何选择不同的这个字段,它是一个整数而不是日期时间?我想选择每天。喜欢member字段的总和,注册于20140603。

在数据库上:

Member    | Processed_Date

A | 1401847266 //real date 20140604

B | 1401846898 //real date 20140604

C | 1401844093 //real date 20140604

D | 1401788219 //real date 20140603

E | 1401788219 //real date 20140603

我要显示的结果:

Date     | Member

20140603 | 2
20140604 | 3

附言。processeddate是日期时间格式转换成时间整数,不是日期格式。

最佳答案

您可以使用 FROM_UNIXTIME() 将整数值转换为日期时间值,然后使用 YEAR()MONTH()DAY() 就可以了。但是,当在列上使用函数时,MySQL 不能再使用索引了。最好是像这样转换其他值:

...
WHERE your_column BETWEEN UNIX_TIMESTAMP('2014-06-04 00:00:00') AND UNIX_TIMESTAMP('2014-06-04 23:59:59');

编辑:

你想做的事情可以通过这个查询来实现:

select
date(from_unixtime(Processed_Date)) as date, count(*) as member
from your_table
group by date

关于mysql - SQL 中的不同时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24032155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com