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" 哪里有错
时间: 2024-02-14 13:24:43 浏览: 108
在这个 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;
阅读全文