如何在MySQL中的选择中使用if/else条件 [英] How to use if/else condition in a select in mysql
本文介绍了如何在MySQL中的选择中使用if/else条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在mysql中的select语句上使用if/else条件?
How can I use an if/else condition on a select statement in mysql?
如果Type ="Initial Read",Select the Initial Column from table_name
否则,如果Type ="Final Read",Select the Final Column from table_name
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?
推荐答案
使用CASE
SELECT CASE Type
WHEN "Initial Read" THEN Initial_Column
WHEN "Final Read" THEN Final_Column
END column
FROM table_name
WHERE <some condition>
这篇关于如何在MySQL中的选择中使用if/else条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文