问题
How can I use an if/else condition on a select statement in mysql?
If Type = "Initial Read", Select the Initial Column from table_name
else if Type = "Final Read", Select the Final Column from table_name
How should I do this? And what is the right query for this? Do i use case select?
回答1:
Use CASE
SELECT CASE Type
WHEN "Initial Read" THEN Initial_Column
WHEN "Final Read" THEN Final_Column
END column
FROM table_name
WHERE <some condition>
来源:https://stackoverflow.com/questions/18927247/how-to-use-if-else-condition-in-a-select-in-mysql