我有2个表名为master和client 我的主表看起来像:
+-----------+---------+--------+--------+--------+-----------------+------------+---------+
| name | mall_id | type | start | end | 1_start | 1_end | item_count | Task_id |
+-----------+---------+--------+--------+--------+-----------------+------------+---------+
| Straight6 | 7 | A | 561 | 728 | NULL | NULL | 1 | 1 |
| Straight6 | 7 | A | 19 | 97 | NULL | NULL | 1 | 1 |
| Straight8 | 7 | B | 58 | 100 | NULL | NULL | 2 | 1 |
| Straight9 | 7 | B | 51 | 110 | NULL | NULL | 3 | 1 |
+-----------+---------+--------+--------+--------+-----------------+------------+---------+
我的客户端表格如下:
+-----------+-------+----+------+-------+-------+---------+------+
| name | item | id |train | start | end | pick_id | type |
+-----------+-------+----+------+-------+-------+---------+------+
| Straight6 | 1 | 1 | 4 | 561 | 080 | 7 | A |
| Straight6 | 2 | 1 | 5 | 561 | 610 | 7 | A |
| Straight6 | 3 | 2 | 4 | 311 | 431 | 7 | A |
| Straight8 | 1 | 1 | 5 | 561 | 610 | 7 | A |
| Straight8 | 3 | 2 | 4 | 311 | 431 | 7 | A |
| Straight9 | 6 | 2 | 4 | 311 | 431 | 7 | A |
| Straight9 | 3 | 2 | 4 | 311 | 431 | 7 | A |
+-----------+-------+----+------+-------+-------+---------+------+
我想将主表的item_count与客户端表中的商品值进行比较,在客户表中进行更改
我想要做的改变是:
当主表中的item_count = 1且客户表中的项> 1时,我希望将项目> 1中的所有这些条目替换为item = 1
(所以对于例如:这里我将替换客户表中有2项条目> 1的
)所以我用这个查询来查找条目:
代码:
select distinct m.name, item_count, item
from master m
join client p
on m.name=p.name
where item_count = 1 and item > 1;
但我应该如何更新它们呢?
更新表格客户端设置项目= 1其中m.name = p.name和item_count = 1 AND item> 1;
这是错的吗?