优化EXISTS方法之后的查询熟读
时间: 2023-08-18 22:09:04 浏览: 114
经过优化后的查询语句如下:
```sql
SELECT
T4.GROUP_CODE || '&' || T4.GROUP_SEQ || '&' || T2.SOURCE_ID AS MKEY,
T4.GROUP_NAME AS VAL
FROM
T_CO_TECHNICS_ROUTE_GROUP T3
LEFT JOIN T_CO_TECHNICS_ROUTE_CONTROL T2 ON T2.TECH_ID = T3.TECH_ID
AND T2.SOURCE_ID = T3.ID
LEFT JOIN T_CO_TECHNICS_ROUTE_GROUP T4 ON T2.TECH_ID = T4.TECH_ID
AND T2.TARGET_ID = T4.ID
WHERE
T3.GROUP_CODE = 'M330'
AND T3.DATA_AUTH = 'FA174AFF136D496A87B65443D22357E3'
AND EXISTS (
SELECT 1
FROM T_WIP_TRACKING B
LEFT JOIN T_WIP_DETAIL C ON C.MO_NUMBER = B.MO_NUMBER
AND B.PRO_SN = C.PRO_SN
AND B.DATA_AUTH = C.DATA_AUTH
WHERE
B.PRO_SN = 'H8408L11402P72600286'
AND B.DATA_AUTH = 'FA174AFF136D496A87B65443D22357E3'
AND C.GROUP_CODE = T4.GROUP_CODE
AND C.GROUP_SEQ = T4.GROUP_SEQ
AND C.DATA_AUTH = T3.DATA_AUTH
AND C.TECH_ID = T3.TECH_ID
)
```
这个优化后的查询语句对于EXISTS子查询优化了表别名的使用,并将子查询中的表关联条件直接放在子查询的WHERE子句中。这样可以减少不必要的连接和子查询,提高查询的执行效率。
阅读全文