优化select * from fxbg_sdqz_bjmb where xxh = 86991004 and xdh = 221 and bjh in ( select distinct bjh from fx_ks_sts_bj where TESTH =299 AND xxh = 86991004 and xdh = 222 AND mbid in ('05474827b50945f3a9b5c7f203b1ef71','362a11e6b4274aae9cb84a43d70eee56'))
时间: 2024-04-14 19:29:39 浏览: 59
您可以对这个SQL查询进行优化,使用JOIN语句来替代子查询,如下所示:
```sql
SELECT f.*
FROM fxbg_sdqz_bjmb f
JOIN fx_ks_sts_bj k ON f.bjh = k.bjh
WHERE f.xxh = 86991004
AND f.xdh = 221
AND k.TESTH = 299
AND k.xxh = 86991004
AND k.xdh = 222
AND k.mbid IN ('05474827b50945f3a9b5c7f203b1ef71', '362a11e6b4274aae9cb84a43d70eee56')
```
这样,通过使用JOIN语句,可以将两个表连接起来,并在连接条件上进行筛选,避免了使用子查询。这样的查询通常比使用子查询更高效。
阅读全文