SELECT LCBH FROM formtable_main_203 where REQUESTID IN (SELECT REQUESTID FROM workflow_requestoperatelog WHERE OPERATORID = '65759' AND OPERATECODE = '5') union SELECT LCBH FROM formtable_main_419 where REQUESTID IN (SELECT REQUESTID FROM workflow_requestoperatelog WHERE OPERATORID = '65759' AND OPERATECODE = '5') 优化此sql
时间: 2023-12-10 20:40:00 浏览: 62
SQL 的 SELECT 语句优化
可以尝试将子查询改为使用 JOIN 操作,避免使用子查询:
```
SELECT LCBH
FROM (
SELECT REQUESTID, LCBH
FROM formtable_main_203
UNION
SELECT REQUESTID, LCBH
FROM formtable_main_419
) t1
JOIN workflow_requestoperatelog t2 ON t1.REQUESTID = t2.REQUESTID
WHERE t2.OPERATORID = '65759' AND t2.OPERATECODE = '5'
```
此外,如果需要加速查询,可以考虑对操作日志表 workflow_requestoperatelog 的 OPERATORID 和 OPERATECODE 字段加上索引。
阅读全文