我正在寻找创建 MySQL 查询的帮助。我有以下数据库表:
+----------------+-----------+-------------+------------+-------------------+---------+-------------+---------------+--------+
| option_type_id | option_id | sku | sort_order | customoptions_qty | default | in_group_id | dependent_ids | weight |
+----------------+-----------+-------------+------------+-------------------+---------+-------------+---------------+--------+
| 552 | 137 | 13071727 | 1000 | 0 | 0 | 0 | | 0.0000 |
| 553 | 137 | 13071727B | 1000 | 0 | 0 | 1 | | 0.0000 |
| 554 | 137 | 13071727C | 1000 | 1 | 0 | 2 | | 0.0000 |
| 555 | 137 | 13071727D | 1000 | 1 | 0 | 3 | | 0.0000 |
| 556 | 138 | 13085350-1 | 1000 | 0 | 0 | 0 | | 0.0000 |
| 557 | 138 | 13085350-1D | 1000 | 2 | 0 | 1 | | 0.0000 |
| 558 | 138 | 13085350-1C | 1000 | 3 | 0 | 2 | | 0.0000 |
| 559 | 138 | 13085350-1B | 1000 | 2 | 0 | 3 | | 0.0000 |
| 560 | 139 | 13069547M | 1000 | 20 | 0 | 0 | | 0.0000 |
| 561 | 140 | 13084477-2 | 950 | 2 | 0 | 0 | | 0.0000 |
| 562 | 140 | 13084477-2B | 951 | 2 | 0 | 1 | | 0.0000 |
| 563 | 140 | 13084477-2C | 952 | 3 | 0 | 2 | | 0.0000 |
| 564 | 140 | 13084477-2D | 953 | 0 | 0 | 3 | | 0.0000 |
| 565 | 140 | 13084477-2E | 954 | 2 | 0 | 4 | | 0.0000 |
| 566 | 141 | 13066533-1 | 1000 | 4 | 0 | 0 | | 0.0000 |
| 567 | 141 | 13066533-1B | 1000 | 5 | 0 | 1 | | 0.0000 |
| 568 | 141 | 13066533-1C | 1000 | 5 | 0 | 2 | | 0.0000 |
| 569 | 141 | 13066533-1D | 1000 | 0 | 0 | 3 | | 0.0000 |
| 570 | 142 | 13071674 | 1000 | 0 | 0 | 0 | | 0.0000 |
| 571 | 142 | 13071674D | 1000 | 1 | 0 | 1 | | 0.0000 |
| 572 | 142 | 13071674C | 1000 | 2 | 0 | 2 | | 0.0000 |
| 573 | 142 | 13071674B | 1000 | 0 | 0 | 3 | | 0.0000 |
| 574 | 142 | 13071674E | 1000 | 4 | 0 | 4 | | 0.0000 |
| 575 | 143 | 13071667 | 1000 | 0 | 0 | 0 | | 0.0000 |
| 576 | 143 | 13071667B | 1000 | 0 | 0 | 1 | | 0.0000 |
| 577 | 143 | 13071667C | 1000 | 0 | 0 | 2 | | 0.0000 |
| 578 | 143 | 13071667D | 1000 | 0 | 0 | 3 | | 0.0000 |
| 579 | 143 | 13071667E | 1000 | 0 | 0 | 4 | | 0.0000 |
| 580 | 144 | 13066295 | 1000 | 1 | 0 | 0 | | 0.0000 |
+----------------+-----------+-------------+------------+-------------------+---------+-------------+---------------+--------+
我想做的是更新in_group_id
= 0的所有行,以A
在sku
. 但是,我只想对没有唯一option_id
值的行执行此操作。
例如,您可以看到option_id
= 139 的行是唯一具有此option_id
值的行,因此我想排除更新此行。
Basically this is a list of product options, some products have multiple options each with it's own SKU. However for these products that have multiple options there is an 'A' missing from the end of the 1st option's SKU, and I'd like to add it. But I don't wish to add an 'A' to products that only have 1 option. I hope this makes sense.
If someone could advise on the MySQL statement that could achieve this, that would be great!