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

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 に答える