自从去年四月离开大学后,不知怎么的,我变得更加不称职了。我有一个我认为应该是一个非常简单的任务:我有很多重复的条件在这OR
MySQL语句的两边。如何将适用于OR
两侧的条件组合在一起?
WHERE (
v_xr_drives.driveisvirtual LIKE "%1%" /*If it's a virtual drive...*/
AND
eventblacklist.`eventblacklistid` > 0
AND
(
eventlogs.source LIKE 'disk'
)
AND
timegen > date_sub(CURRENT_DATE(), interval 1 day)
AND
eventlogs.message NOT LIKE "%during a paging operation%"
AND
eventlogs.message NOT LIKE "%controller error%" /*...then I don't want rows returned for drive controller errors.*/
)
OR
(
v_xr_drives.driveisvirtual LIKE "%0%" /*But if it's a physical drive...*/
AND
eventblacklist.`eventblacklistid` > 0
AND
(
eventlogs.source LIKE 'disk'
)
AND
timegen > date_sub(CURRENT_DATE(), interval 1 day)
AND
eventlogs.message NOT LIKE "%during a paging operation%"
/*...then I still want rows returned for drive controller errors (thus omitting the 'NOTLIKE "%controller error%"' condition from above*/
)
您只需将它们与OR的结果进行AND运算:
WHERE
((
v_xr_drives.driveisvirtual LIKE "%1%" /*If it's a virtual drive...*/
AND
eventlogs.message NOT LIKE "%controller error%" /*...then I don't want rows returned for drive controller errors.*/
)
OR
(
v_xr_drives.driveisvirtual LIKE "%0%" /*But if it's a physical drive...*/
))
AND
eventblacklist.`eventblacklistid` > 0
AND
(
eventlogs.source LIKE 'disk'
)
AND
timegen > date_sub(CURRENT_DATE(), interval 1 day)
AND
eventlogs.message NOT LIKE "%during a paging operation%"