0
我在我的magento數據庫中創建了一個查詢,以查找具有「New From」dat但沒有「New To」的產品。選擇with innerjoin和動態更新
SELECT
catalog_product_entity.entity_id,
catalog_product_entity.sku,
a.value as New_From,
b.value as New_To
FROM `catalog_product_entity`
INNER JOIN catalog_product_entity_datetime as a on a.entity_id = catalog_product_entity.entity_id and a.attribute_id = '93'
INNER JOIN catalog_product_entity_datetime as b on b.entity_id = catalog_product_entity.entity_id and b.attribute_id = '94'
WHERE a.value IS NOT NULL AND b.value IS NULL
現在我想什麼來完成,因爲它涉及500多個項目在此查詢結束運行UPDATE語句「新能」有1個月後已經打開。
任何想法如何運行?
所以澄清:
表1:(catalog_product_entity)
| entity_id | sku |
| --------- | --- |
| 1 | ABC |
| 2 | DEF |
表2:(catalog_product_entity_datetime)
| id | entity_id | attribute_id | value |
| --- | --------- | ------------ | ----- |
| 1 | 1 | 93 | 2013-06-12 00:00:00 |
| 2 | 1 | 94 | 2013-07-12 00:00:00 |
| 3 | 1 | 98 | Some other attribute |
| 4 | 2 | 93 | 2014-08-20 00:00:00 |
| 5 | 2 | 94 | NULL | <- This I want updating
| 6 | 2 | 98 | Some other attribute |
我想更新在表2中與所述NULL值來自同一張表+ 1個月的日期。我的搜索返回:
| entity -id | sku | New_From | New_To |
| ----------- | --- | ------------------- | ------------------- |
| 2 | DEF | 2014-08-20 00:00:00 | NULL |
所以我想編寫將該字段更新爲New_From + 1個月的查詢。
| entity -id | sku | New_From | New_To |
| ----------- | --- | ------------------- | ------------------- |
| 2 | DEF | 2014-08-20 00:00:00 | 2014-09-20 00:00:00 |
在我的腦海裏,我將最終的東西是這樣的:(但是這一次不工作)
UPDATE catalog_product_entity_datetime
SET value = TIMESTAMP(a.value+300000000)
INNER JOIN catalog_product_entity_datetime as a on a.entity_id = catalog_product_entity_datetime.entity_id and a.attribute_id = '93'
WHERE attribute_id=94
你的問題不清楚,向我們展示一些樣品數據和您想要的結果。 – Blank
我添加了一些表來解釋@JPG – Jacco