如果我在数据库中名为creation_date
的表中有一列包含unix时间戳值,那么如何返回仅在例如May 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';
答案 0 :(得分: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');