正如标题所说,使用 DATE 和 DATETIME 进行选择时,行数会有所不同。请指教。
我正在尝试选择 2012 年 1 月 1 日到 5 日之间的行。日期列数据类型是 bigint(UNIX 时间戳)。
select * from table_name
where sample_timestamp between unix_timestamp('2012-01-01')*1000 and unix_timestamp('2012-01-05')*1000
如果我在 HH:MM:SS 中包含时间,则返回的行是正确的,即
select * from table_name
where sample_timestamp between unix_timestamp('2012-01-01 00:00:00')*1000 and unix_timestamp('2012-01-05 23:59:59')*1000
任何输入将不胜感激。谢谢。
最佳答案
“2012-01-05”实际上是“2012-01-05 00:00:00”,这不是您在第二个选择中写的内容。
我怀疑你的意思是
select * from table_name
where sample_timestamp >= unix_timestamp('2012-01-01')*1000
and sample_timestamp < unix_timestamp('2012-01-06')*1000
作为奖励,它也能正确处理闰秒 :)
关于mysql - 使用 DATE 和 DATETIME 时行数不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8975321/