update xc_device_bind_agent a left join waibu_agent b on a.agent = b.server left join gps.ascriptionserver c on b.server = c.server set a.agent = CASE WHEN `c.CompanyName` is not null THEN `c.CompanyName` ELSE b.name where b.name is not null; 这里面哪里语法错了
时间: 2024-03-15 20:45:54 浏览: 59
这个 SQL 语句中有一个语法错误,应该将 `ELSE` 关键字与 `WHERE` 关键字分开。修改后的语句如下:
```
UPDATE xc_device_bind_agent a
LEFT JOIN waibu_agent b ON a.agent = b.server
LEFT JOIN gps.ascriptionserver c ON b.server = c.server
SET a.agent = CASE
WHEN c.CompanyName IS NOT NULL THEN c.CompanyName
ELSE b.name
END
WHERE b.name IS NOT NULL;
```
修改后的语句中,将 `ELSE` 关键字和 `WHERE` 关键字分开,并在 `CASE` 语句中添加了 `END` 关键字。同时,为了保持代码的可读性,对 SQL 语句进行了适当的格式化。
相关问题
SELECT e.company company, e.imsi imsi, e.iccId iccId,f.agent agent, f.iccId FROM xc_sim_biill_detail e LEFT JOIN ( SELECT d.agent agent, c.imei imei, c.iccId iccId, c.imsi imsi FROM xc_device_bill a LEFT JOIN xc_bill_imei b ON a.bill_no = b.bill_no LEFT JOIN ( SELECT t.iccId, t.imsi, t.imei FROM xc_device_info t JOIN ( SELECT imsi, MAX(production_time) AS production_time FROM xc_device_info GROUP BY imsi ) sub ON t.imsi = sub.imsi AND t.production_time = sub.production_time ) c ON b.imei = c.imei LEFT JOIN xc_device_bind_agent d ON c.imei = d.imei ) f ON f.iccId = e.iccId WHERE f.agent != e.company; where e.simExpireDate >= "2023-06-01 00:00:00" and e.simExpireDate <= "2023-06-30 23:59:59" 哪里有错
在这个 SQL 查询语句中,WHERE 关键字应该放在 JOIN 子句之后,而不是在 JOIN 子句之前。因此,正确的查询语句应该是:
SELECT e.company company, e.imsi imsi, e.iccId iccId, f.agent agent, f.iccId
FROM xc_sim_biill_detail e
LEFT JOIN (
SELECT d.agent agent, c.imei imei, c.iccId iccId, c.imsi imsi
FROM xc_device_bill a
LEFT JOIN xc_bill_imei b ON a.bill_no = b.bill_no
LEFT JOIN (
SELECT t.iccId, t.imsi, t.imei
FROM xc_device_info t
JOIN (
SELECT imsi, MAX(production_time) AS production_time
FROM xc_device_info
GROUP BY imsi
) sub ON t.imsi = sub.imsi AND t.production_time = sub.production_time
) c ON b.imei = c.imei
LEFT JOIN xc_device_bind_agent d ON c.imei = d.imei
) f ON f.iccId = e.iccId
WHERE e.simExpireDate >= "2023-06-01 00:00:00" AND e.simExpireDate <= "2023-06-30 23:59:59" AND f.agent != e.company;
阅读全文