select * from Integrity res where id_no=’14262319731215081X’ and sta in (0,4) and update _time<='2023-05-23 13:09:58' ,and result_code='0000 and func_no='123';优化
时间: 2023-11-28 13:47:06 浏览: 70
首先,建议在 `id_no` 字段上创建索引以提高查询性能。另外,可以将 `update_time` 字段的条件放在 `id_no` 和 `sta` 的条件之前,以利用索引。最后,根据情况可以考虑使用 UNION ALL 将 `func_no` 不同的查询分开执行。
修改后的 SQL 语句如下:
```
SELECT *
FROM Integrity res
WHERE id_no = '14262319731215081X' AND sta IN (0, 4)
AND update_time <= '2023-05-23 13:09:58' AND result_code = '0000'
AND func_no = '123';
```
如果需要查询多个 `func_no`,可以使用以下 SQL 语句:
```
SELECT *
FROM (
SELECT *
FROM Integrity res
WHERE id_no = '14262319731215081X' AND sta IN (0, 4)
AND update_time <= '2023-05-23 13:09:58' AND result_code = '0000'
AND func_no = '123'
UNION ALL
SELECT *
FROM Integrity res
WHERE id_no = '14262319731215081X' AND sta IN (0, 4)
AND update_time <= '2023-05-23 13:09:58' AND result_code = '0000'
AND func_no = '456'
-- Add more UNION ALL clauses for additional func_no values
) AS all_results;
```
阅读全文