WITH
t AS (SELECT _number,
MAX(_address) AS _address -- here can be more than one row with type = 0 ?
FROM test
WHERE _type = 0
GROUP BY _number)
SELECT test._id,
test._number,
test._type,
t._address
FROM test
LEFT JOIN t
ON test._number = t._number;
UPDATE test
INNER JOIN (SELECT
_number,
max(_address) AS _address -- here can be more than one row with type = 0 ?
FROM test
WHERE _type = 0
GROUP BY _number) t
ON t._number = test._number
SET test._address = t._address;
1条答案
按热度按时间ltskdhd11#
如下所示(取type = 0的number的值,并将其联接到主表):
下面是dbfiddle示例
**upd.**对于更新,您可以使用以下更新:
已更新dbfiddle here