我想编写一个带有多个参数的 MySQL 优化查询。一个参数可能是null
. 如果是null
该过程应该返回所有行。否则它应该只返回特定的行。这是我到目前为止所拥有的:
where
wsj.`IsVerified`=1
and
if (FindWhere != NULL)
then
begin
wsj.`ExpectedLocation` like
Concat('%',ifnull(FindWhere,wsj.`ExpectedLocation`),'%')
or wsj.`CurrentLocation` like
Concat('%',ifnull(FindWhere,wsj.`CurrentLocation`),'%')
or wsl.`City` like
Concat('%',ifnull(FindWhere,wsl.`City`),'%')
or wsl.`State` like
Concat('%',ifnull(FindWhere,wsl.`State`),'%')
or wsl.`Country` like
Concat('%',ifnull(FindWhere,wsl.`Country`),'%')
end
END IF;