mysql条件查询语句between and和in的效率比较

工作需要,写按sensor_uuid在某范围查询的语句:

1.select * from xz_sensor_data where sensor_time>='2019-03-28 00:00:00.000' and sensor_time<='2019-03-28 08:00:00.000' and sensor_uuid in('20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','201901','201902','201903','201904','201905','201906','201907','201908','201909','201910','201911','201912','201913')  order by sensor_time asc

2.select * from xz_sensor_data where sensor_time>='2019-03-28 00:00:00.000' and sensor_time<='2019-03-28 08:00:00.000' and (sensor_uuid  between '19' and '36' or sensor_uuid between '201900' and '201914' )

发现第二条执行效率高。

猜你喜欢

转载自blog.csdn.net/qq_31220649/article/details/88885081
今日推荐