在Mysql中获取当前unix时间戳所在的记录

在Mysql中获取当前unix时间戳所在的记录,mysql,unix-timestamp,Mysql,Unix Timestamp,我将记录存储在msyql中,其中resolve_by列具有unix时间戳 我正在尝试以下查询: SELECT id FROM tickets WHERE FROM_UNIXTIME('resolve_by','%Y-%m-%d') = CURDATE() 基本表结构是: id|resolve_by|date_created 4, 1506092040, 1506084841 但这将返回0条记录。如何获取unix时间戳值=今天日期的记录 谢谢,更改了以下查询: SELECT id FROM t

我将记录存储在msyql中,其中resolve_by列具有unix时间戳

我正在尝试以下查询:

SELECT id FROM tickets WHERE FROM_UNIXTIME('resolve_by','%Y-%m-%d') = CURDATE()
基本表结构是:

id|resolve_by|date_created
4, 1506092040, 1506084841
但这将返回0条记录。如何获取unix时间戳值=今天日期的记录

谢谢,

更改了以下查询:

SELECT id FROM tickets WHERE FROM_UNIXTIME('resolve_by','%Y-%m-%d') = CURDATE()
致:


它现在可以工作了。

通常,您希望避免在
的列侧使用函数,因为它很可能会取消查询从索引中获益的资格

考虑以下情况:

create table test_table ( id varchar(36) primary key, ts timestamp );

insert into test_table (id,ts) values('yesterday',     current_timestamp - interval 1 day);
insert into test_table (id,ts) values('midnight',      current_date);
insert into test_table (id,ts) values('now',           current_timestamp);
insert into test_table (id,ts) values('next midnight', current_date + interval 1 day);
insert into test_table (id,ts) values('tomorrow',      current_timestamp + interval 1 day);

create index test_table_i1 on test_table (ts);

select *
  from test_table
 where ts >= current_date
   and ts <  current_date + interval 1 day;
;

如果您对排除下一个午夜不太挑剔(
between
接受两个边界)

您可以与一些数据共享数据库基本结构吗。。??
create table test_table ( id varchar(36) primary key, ts timestamp );

insert into test_table (id,ts) values('yesterday',     current_timestamp - interval 1 day);
insert into test_table (id,ts) values('midnight',      current_date);
insert into test_table (id,ts) values('now',           current_timestamp);
insert into test_table (id,ts) values('next midnight', current_date + interval 1 day);
insert into test_table (id,ts) values('tomorrow',      current_timestamp + interval 1 day);

create index test_table_i1 on test_table (ts);

select *
  from test_table
 where ts >= current_date
   and ts <  current_date + interval 1 day;
;
select *
  from test_table
 where ts between current_date and current_date + interval 1 day;