在函数里面一个修改的语句where后面动态拼接条件,应该如何使用啊!
CASE
WHEN repeatType = 1 THEN date_format(.....
类似语法的问题可以直接参考MYSQL官方免费手册
CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result ...] [ELSE result] END
CASE WHEN [condition] THEN result [WHEN [condition] THEN result ...] [ELSE result] END
The first version returns the result where value=compare_value. The second version returns the result for the first condition that is true. If there was no matching result value, the result after ELSE is returned, or NULL if there is no ELSE part.
mysql> SELECT CASE 1 WHEN 1 THEN 'one'
-> WHEN 2 THEN 'two' ELSE 'more' END;
-> 'one'
mysql> SELECT CASE WHEN 1>0 THEN 'true' ELSE 'false' END;
-> 'true'
mysql> SELECT CASE BINARY 'B'
-> WHEN 'a' THEN 1 WHEN 'b' THEN 2 END;
-> NULL
The default return type of a CASE expression is the compatible aggregated type of all return values, but also depends on the context in which it is used. If used in a string context, the result is returned as a string. If used in a numeric context, then the result is returned as a decimal, real, or integer value.
Note
The syntax of the CASE expression shown here differs slightly from that of the SQL CASE statement described in Section 12.8.6.2, “CASE Statement”, for use inside stored programs. The CASE statement cannot have an ELSE NULL clause, and it is terminated with END CASE instead of END.
mysql根据不同年龄组的BMI值判断是否肥胖语句
如图所示,如何把性别9001002年龄12岁的学生,其BMi大于17则在obesity显示3,小于16.4则显示1,17至16.4显示2