[英]How to write a MYSQL CASE WHEN statement with multiple search conditions?
I know languages like PHP has switch case control structure that supports multiple validations in a single case statement like, 我知道像PHP这样的语言有一个switch case控制结构,支持在单个case语句中进行多次验证,比如
Switch $x {
case 1,2,3:
$a = 0;
break;
case 5,6:
$a = 1;
break;
}
Similarly can this be done in MYSQL? 同样可以在MYSQL中完成吗? I tried below, which really didn't work though :(
我试过下面,虽然真的没有用:(
CASE vc_shape
WHEN ('02' OR '51') THEN SET dc_square_1 = dc_square_1 + dc_row_total;
WHEN ('06' OR '30' OR 83) THEN SET dc_square_2 = dc_square_2 + dc_row_total;
.....
.....
ELSE
BEGIN
END;
END CASE;
Any ideas how can I achieve this? 任何想法我怎样才能做到这一点?
Use the other format for CASE
statements: 使用
CASE
语句的其他格式:
CASE
WHEN vc_shape IN ('02', '51') THEN SET dc_square_1 = dc_square_1 + dc_row_total;
WHEN vc_shape IN ('06', '30', '83') THEN SET dc_square_2 = dc_square_2 + dc_row_total;
.....
.....
ELSE
BEGIN
END;
END CASE;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.