SQL SELECT If (a="") 然后更改 b 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16154799/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:56:39 来源:igfitidea点击:
SQL SELECT If (a="") Then change b value
提问by Tyler Mortensen
This seems like a simple question, but I haven't been able to find an answer. I am basically trying to do this:
这似乎是一个简单的问题,但我一直无法找到答案。我基本上是在尝试这样做:
SELECT * FROM table1
IF(columnA > 0) BEGIN
columnB = 'Greater than 0'
END
I don't want the value to change in the table, I just want it to change in the result. ANy suggestions?
我不希望表中的值发生变化,我只希望它在结果中发生变化。有什么建议?
回答by Kevin Suchlicki
SELECT ColumnA
, case when ColumnA > 0 then 'Greater than 0' else ColumnB END AS ColumnB
FROM table1;
回答by Ted Hopp
This should work:
这应该有效:
SELECT columnA, IIF(columnA > 0, 'Greater than 0', columnB)
FROM table1;