使用IN
SELECT s.* FROM b_cc_work_time_schedule_shift s
WHERE s.schedule_user_id in (
SELECT u.id FROM b_cc_work_time_schedule_user u
WHERE u.tenant_id = '321ff495b20b4345b6003f9688cc80e6'
AND u.date_day BETWEEN '2019-6-27' AND LAST_DAY('2019-6-27')
)
930
条数据0.165s
使用 EXISTS
SELECT s.id FROM b_cc_work_time_schedule_shift s
WHERE EXISTS (
SELECT * FROM b_cc_work_time_schedule_user u
WHERE u.tenant_id = '321ff495b20b4345b6003f9688cc80e6'
AND u.date_day BETWEEN '2019-6-27' AND LAST_DAY('2019-6-27')
AND s.schedule_user_id = u.id
)
930
条数据0.060s
效率方面提升了2.75倍
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/database/5790.html