SELECT WEEK(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1) as order_week,
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1) as order_year
FROM orders_products_attributes
如果只是一周,我没有收到任何错误,但是一旦我尝试选择年份,它就会抛出
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1) as order_year FROM orders_products_attributes'...
我做错了什么?
答案 0 :(得分:1)
替换
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1)
与
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' ))
YEAR()
功能没有第二个参数。或者你可以做到
STR_TO_DATE( products_options_values, '%Y' )
答案 1 :(得分:0)
使用此sql
SELECT WEEK(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1) as order_week,
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' )) as order_year
FROM orders_products_attributes
进一步阅读 http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_year
答案 2 :(得分:0)
YEAR()
方法使用不当。第二个参数不应该存在。
试试这个:
SELECT WEEK(STR_TO_DATE( products_options_values, '%m-%d-%Y' ),1)
as order_week,
YEAR(STR_TO_DATE( products_options_values, '%m-%d-%Y' )) as order_year
FROM orders_products_attributes