CASE语句的问题没有给出正确的值

时间:2014-11-04 19:33:06

标签: sql

我在SQL Developer中使用以下CASE语句:

CASE  
  WHEN ([Medication]="N") AND ([Name]="STYMES") AND ([Original Units] IS NOT NULL) THEN "Y" 
  WHEN ([Medication]="N") AND ([Name]="STYMES") AND ([Original Units] IS NULL) THEN "N" 
  WHEN ([Medication]="Y") AND ([Name]="STYMES") AND ([Original Units] IS NOT NULL) THEN "N" 
  WHEN ([Medication]="Y") AND ([Name]="STYMES") AND ([Original Units] IS NULL) THEN "Y" 
END

当我至少得到N时,我的结果是空的。

1 个答案:

答案 0 :(得分:1)

如果你想要的只是得到一个N'当您的其他条件不满足时,您可以使用ELSE关键字,如:

case  
  when ([Medication]="N") AND ([Name]="STYMES") AND([Original Units] is not null) then "Y" 
  when ([Medication]="N") AND ([Name]="STYMES") AND([Original Units] is null) then "N" 
  when ([Medication]="Y") AND ([Name]="STYMES") AND([Original Units] is not null) then "N" 
  when ([Medication]="Y") AND ([Name]="STYMES") AND([Original Units] is null) then "Y" 
  else "N"
end