sql中between and 、union all、or
between and
union all
or
其中or会导致全表查询,速度很慢
between and 这要快很多。
SELECT
t,
ms,
content,
confirm_status,
ied_id,
VALUE,
stName,
devName
FROM
(
SELECT
temp.*, rownum rn
FROM
(
SELECT
fis.t,
fis.ms,
fis.content,
fis.confirm_status,
fis.ied_id,
fis.VALUE,
sta.name as stName,
ied.name as devName
FROM
${_qrefix}fis_com_status_alarm fis,${_qrefix}substation sta,${_qrefix}fis_ied ied
WHERE
fis.VALUE BETWEEN 1 and 2
AND fis.st_id = #{st_id}
AND fis.IED_ID = ied.id
AND fis.st_id = sta.id
AND fis.t >= #{t_start}
AND fis.t <= #{t_end}
ORDER BY
fis.t DESC,
fis.ms DESC
) temp
WHERE
rownum <= #{row_end}
)
WHERE
rn >= #{row_begin}
这里条件是value=1 和value=2 测试时,用between and 耗时0.05s,用or耗时12.5s