0

如果我creation_date在数据库中调用的表中有一个包含 unix 时间戳值的列,我如何获得仅在 exampleMay 10th 2013和之间创建的返回结果June 9th 2013

我尝试了以下但我得到的只是0; 这是不正确的。

SELECT COUNT(*) FROM my_table WHERE FROM_UNIXTIME(creation_date) BETWEEN '05-10-2013 00:00:00' AND '06-09-2013 23:59:59';
4

1 回答 1

1

1)如果creation_date是一个时间戳存储为TIMESTAMP

SELECT 
  COUNT(*) 
FROM 
  my_table 
WHERE 
  creation_date 
      BETWEEN '2013-05-10 00:00:00' 
      AND '2013-06-09 23:59:59';

2)如果creation_date是一个时间戳存储为INT

SELECT 
  COUNT(*) 
FROM 
  my_table 
WHERE 
  creation_date 
      BETWEEN UNIX_TIMESTAMP('2013-05-10 00:00:00') 
      AND UNIX_TIMESTAMP('2013-06-09 23:59:59');
于 2013-06-14T11:56:55.287 回答