Mysql - selecting year from a unix timestamp

后端 未结 5 611
失恋的感觉
失恋的感觉 2020-12-15 07:07

I am using this:

SELECT FROM_UNIXTIME(my_unix_timestamp_column, \'%Y\') AS year FROM table_name WHERE year = 2009;

but it gives me an error

5条回答
  •  半阙折子戏
    2020-12-15 07:45

    You can't use a column created the SELECT section in your WHERE clause

    replace the year variable in your where clause with the actual function to create that column (aka FROM_UNIXTIME(my_unix_timestamp_column, '%Y') ) and you should be fine.

    This is because the SELECT section of your query isn't executed until the WHERE section has finished matching rows to return.

提交回复
热议问题