2013-07-29 55 views
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 

如果這僅僅是一週,我沒有得到任何錯誤,但只要我儘量選擇一年爲好,它會拋出有什麼毛病我MySQL查詢

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

什麼時我做錯了?

回答

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') 
+0

謝謝...我只注意到它...我傻 – Bluemagica

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')) as order_year 
FROM orders_products_attributes