MySQL timestamp select date range

后端 未结 7 1192
栀梦
栀梦 2021-02-01 14:32

Not sure really where to start with this one. Can anyone help/point me in the right direction.

I have a timestamp column in MySQL and I want to select a date range for e

7条回答
  •  名媛妹妹
    2021-02-01 14:55

    Whenever possible, avoid applying functions to a column in the where clause:

    SELECT *
      FROM table_name
     WHERE timestamp >= UNIX_TIMESTAMP('2010-10-01 00:00:00') 
       AND timestamp <  UNIX_TIMESTAMP('2010-11-01 00:00:00');
    

    Applying a function to the timestamp column (e.g., FROM_UNIXTIME(timestamp) = ...) makes indexing much harder.

提交回复
热议问题