2015-06-09 125 views
-1

選擇運行。我正在嘗試更改更新但不起作用。誰知道幫助我?選擇更新mysql

select 
concat(
'Вы можете приобрести "', pd.name, '" с гарантией от производителя', 
' "', max(case when ad.attribute_id=2 then ad.name end), '" ', 
' "', max(case when ad.attribute_id=2 then pa.text end), '" ', 
' и ', 
' "', max(case when ad.attribute_id=3 then ad.name end), '" ', 
' "', max(case when ad.attribute_id=3 then pa.text end), '" ') 
from 
oc_product_description pd 
inner join oc_product_to_category pc on pd.product_id=pc.product_id 
inner join oc_product_attribute pa on pd.product_id=pa.product_id and pd.language_id=pa.language_id 
inner join oc_attribute_description ad on pa.attribute_id=ad.attribute_id and pa.language_id=ad.language_id 
where 
pd.language_id=4 
and pa.attribute_id in (2,3) 
and pc.category_id=121 
and pd.product_id = 102 

我的更新,我有錯誤#1064 - 您的SQL語法錯誤;檢查對應於你的MySQL服務器版本的「由pd.name集團使用附近的正確的語法在第22行

UPDATE `oc_product_description` pd 
inner join oc_product_attribute pa on pd.product_id=pa.product_id and 

pd.language_id=pa.language_id 
inner join oc_attribute_description ad on pa.attribute_id=ad.attribute_id and 

pa.language_id=ad.language_id 
inner join oc_product_to_category pc on pc.product_id=pa.product_id 

set pd.`description`= concat(
'Вы можете приобрести ', pd.name, ' с гарантией от производителя', 
' ', max(case when ad.attribute_id=2 then ad.name end), ' ', 
' ', max(case when ad.attribute_id=2 then pa.text end), ' ', 
' и ', 
' ', max(case when ad.attribute_id=3 then ad.name end), ' ', 
' ', max(case when ad.attribute_id=3 then pa.text end), ' ') 

where pd.language_id=4 
and pa.attribute_id in (2,3) 
and pc.category_id = 121 
and pa.product_id = 102 
group by pd.name 
+1

嘗試添加更多的細節,因爲現在不清楚你想要達到什麼目標以及你的問題是什麼。請注意,「不起作用」不能被認爲是明確的問題描述。 –

+0

編寫您的更新查詢,那裏可能有邏輯或語法錯誤。 –

+0

我想對這個select.how做一個更新,我不知道。你需要查看我的嘗試? –

回答

0

我做這件事的手冊!

UPDATE oc_product_description pd 
     inner join oc_product_to_category pc on pd.product_id=pc.product_id 
     inner join oc_product_attribute pa on pd.product_id=pa.product_id and pd.language_id=pa.language_id 
     SET pd.`description`=concat(
     'Вы можете приобрести "', pd.name,(
     select 
     concat('" с гарантией от производителя', 
     ' "', max(case when ad2.attribute_id=2 then ad2.name end), '" ', 
     ' "', max(case when ad2.attribute_id=2 then pa2.text end), '" ', 
     ' и ', 
     ' "', max(case when ad2.attribute_id=3 then ad2.name end), '" ', 
     ' "', max(case when ad2.attribute_id=3 then pa2.text end), '" ') 



    from oc_product_attribute pa2 
    inner join oc_attribute_description ad2 on pa2.attribute_id=ad2.attribute_id and pa2.language_id=ad2.language_id 

    where pa2.language_id=pd.language_id 
    and pa2.attribute_id in (2,3) 
    and pa2.product_id = pd.product_id 
    )) 
    where 
    pd.language_id=4 
    and pa.attribute_id in (2,3) 
    and pc.category_id=121 
    and pd.product_id = 102