0
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'...

我究竟做错了什么?

4

3 回答 3

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' )
于 2013-07-29T10:29:37.387 回答
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

于 2013-07-29T10:54:34.463 回答
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
于 2013-07-29T11:06:15.950 回答