Select only year from MySql

前端 未结 3 1620
遇见更好的自我
遇见更好的自我 2020-12-21 18:57

I need to select only the year from the record date.

SELECT *, DATE_FORMAT(\'release\',\'%Y\') AS release_year FROM books

but doesnt work.

3条回答
  •  天命终不由人
    2020-12-21 19:29

    Don't put release in quotes. You're trying to extract the year from a literal string 'release', not the value in the column `release`.

    And as @invisal states, RELEASE is a reserved word in MySQL, so you have to delimit it with back-ticks.

提交回复
热议问题