以下更新查询无效,但内部的选择查询为:
UPDATE tb_alunos_detalhes A
SET A.ADTELALUNO = B.TEL
FROM B (
SELECT ADID ID,
(CASE
WHEN `ADTELALUNO` <> '' THEN ( CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(`ADTELALUNO`, ' ', 1), ' ', -1), ' 9-', SUBSTRING(SUBSTRING_INDEX(SUBSTRING_INDEX(`ADTELALUNO`, ' ', 2), ' ', 10),6,10)))
ELSE ''
END) TEL
FROM tb_alunos_detalhes ) B
WHERE A.ADID = B.ID
它给了我以下错误:
意外的令牌。 (靠近&#34;(&#34;在62位) 发现了一个新的声明,但它与前一个声明之间没有分隔符。 (在&#34; SELECT&#34;在67位) 意外的标记。 (近&#34;)&#34;在第381位) 意外的标记。 (在&#34; B&#34;在383位置附近)
我做错了什么?
答案 0 :(得分:0)
您可能正在寻找像
这样的update-join
语法
UPDATE tb_alunos_detalhes A
JOIN (
SELECT ID,
(CASE
WHEN `ADTELALUNO` <> '' THEN ( CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(`ADTELALUNO`, ' ', 1), ' ', -1), ' 9-', SUBSTRING(SUBSTRING_INDEX(SUBSTRING_INDEX(`ADTELALUNO`, ' ', 2), ' ', 10),6,10)))
ELSE ''
END) TEL
FROM tb_alunos_detalhes ) B ON A.ADID = B.ID
SET A.ADTELALUNO = B.TEL;
答案 1 :(得分:0)
use this for reference , and i think this will work for you
UPDATE(
SELECT Ord.OrderID, Ord.Completed
FROM Order1 Ord
WHERE EXISTS(
SELECT *
FROM Product P
INNER JOIN Delivery D
ON Delivery.Delivered = 0 AND P.ProductID = Delivery.DeliveryID
WHERE Ord.OrderID = P.OrderID
)
)
SET Completed = 'NO' ;
//或没有派生表:
UPDATE Order1 Ord
SET Completed = 'NO'
WHERE EXISTS(
SELECT *
FROM Product P
INNER JOIN Delivery D
ON Delivery.Delivered = 0 AND P.ProductID = Delivery.DeliveryID
WHERE Ord.OrderID = P.OrderID
);
答案 2 :(得分:0)
正确的语法是:
UPDATE tb_alunos_detalhes A
SET A.ADTELALUNO = (CASE WHEN `ADTELALUNO` <> ''
THEN ( CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(`ADTELALUNO`, ' ', 1), ' ', -1), ' 9-', SUBSTRING(SUBSTRING_INDEX(SUBSTRING_INDEX(`ADTELALUNO`, ' ', 2), ' ', 10),6,10)))
ELSE ''
END);
不需要JOIN
。