简体   繁体   English

选择中的条件语句

[英]Condition statement in a select

Here's what i wanna do这就是我想做的

Select X, Y, if Z IS NULL THEN ( select something ) else Z

Basically I want to select the 'Z' if it's null I want to select another value, can someone please suggest a code example with a case or something that I can follow through it ?基本上我想选择'Z',如果它为空我想选择另一个值,有人可以建议一个带有案例的代码示例或我可以遵循它的东西吗?

Do you want coalesce() ?你想要coalesce()吗?

Select X, Y,
       coalesce(z, <something else>) as z
Select X, Y, NVL(Z, showThis) as Z

will return showThis if Z is null in ORACLE如果在ORACLE 中Z为空,将返回showThis

Select X, Y, ISNULL(Z, showThis) as Z

will return showThis if Z is null in SQL-SERVER如果ZSQL-SERVER 中为空,将返回showThis

Choose with CASE:选择与案例:

select 
  X, Y, 
  case 
    when Z is null then (select something)
    else (select something else)
  end as col
from tablename

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM