[英]How to make my code more efficient (beginner :)
can someone suggest a shorter code that does the same?有人可以建议一个更短的代码吗?
CASE
WHEN {location} LIKE '%00' OR {location} LIKE '%010' OR {location} LIKE '%011' OR {location} LIKE '%012' OR {location} LIKE '%013' THEN '1'
WHEN {location} LIKE '%38' OR {location} LIKE '%039' OR {location} LIKE '%040' OR {location} LIKE '%041' OR {location} LIKE '%042' OR {location} LIKE '%043' OR {location} LIKE '%044' OR {location} LIKE '%046' OR {location} LIKE '%047' THEN '2'
ELSE '3'
END
instead fo several OR you could try using between range相反,您可以尝试在范围之间使用多个或
CASE when substr({location}, -2) ='00'
or cast(substr({location}, -2)) AS UNSIGNED )between 10 and 13 then '1'
when cast(substr({location}, -2)) AS UNSIGNED) between 38 and 47 then '2'
else '3'
end
If you are using a database that supports regular expressions then you can simplify this considerably.如果您使用的是支持正则表达式的数据库,那么您可以大大简化它。 For instance, in MySQL:例如,在 MySQL 中:
(CASE WHEN {location} REGEXP '00$|010$|011$|012$|013$' THEN '1'
WHEN {location} REGEXP '38$|039$|040$|041$|042$|043$|044$|046$|047$' THEN '2'
ELSE '3'
END)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.