如何在mysql的select语句中使用if / else条件?
如果Type =“Initial Read”,Select the Initial Column from table_name
否则如果Type =“Final Read”,Select the Final Column from table_name
我该怎么做?什么是正确的查询?我是否使用案例选择?
答案 0 :(得分:2)
使用CASE
SELECT CASE Type
WHEN "Initial Read" THEN Initial_Column
WHEN "Final Read" THEN Final_Column
END column
FROM table_name
WHERE <some condition>