我需要在mysql查询中嵌套if-else条件的示例
答案 0 :(得分:8)
您还可以使用if-else条件的案例陈述
SELECT
(CASE field1
WHEN 'A' THEN 'value is A'
WHEN 'B' THEN 'value is B'
ELSE 'value is neither A or B'
END)
FROM your_table;
或
SELECT
(CASE
WHEN (field1 IS NULL) THEN 'value is NULL'
WHEN (field1 = 1) THEN 'value is 1'
ELSE 'value is neither NULL or 1'
END)
FROM your_table;
答案 1 :(得分:4)
您的意思是IF( expr , expr , expr )功能为defined here?一个例子是:
SELECT
name, ID,
IF(category = 'fulltime', 1,
IF(category = 'parttime', loading, 0)) AS equivloading
FROM
person