case when 不用else
时间: 2023-10-15 19:24:04 浏览: 105
sql学习之CASE WHEN THEN ELSE END的用法
当使用case when语句时,如果不写else,匹配不上的结果将默认为NULL。
例如,在第一个例子中,如果不写else,则匹配结果为NULL:
```
select case 1 when 1 then "yes" end as test
```
在第二个例子中,如果不写else,则匹配不上的结果为NULL:
```
select case 0 when 1 then "yes" end as test
```
同样地,在UPDATE语句中,如果没有else语句,并且没有列出的条件匹配,那么结果会被设置为NULL:
```
UPDATE jxgd.yw_shiyanshuju
SET JXYP2159184=CASE
WHEN JXYP2159184='TA' THEN 'AT'
WHEN JXYP2159184='TC' THEN 'CT'
WHEN JXYP2159184='TG' THEN 'GT'
WHEN JXYP2159184='GA' THEN 'AG'
WHEN JXYP2159184='GC' THEN 'CG'
WHEN JXYP2159184='CA' THEN 'AC'
END;
```
注意,在这种情况下,为了增加用户的便捷性,我们可以为插入代码片段添加一个漂亮的样式。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [【Hive】 case when 语句如果 不写else 匹配不上的默认输为NULL](https://blog.csdn.net/iiiitttttt/article/details/124689908)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [SQL CASE WHEN 没有ELSE的用法SQL CASE WHEN WITHOU ELSE](https://blog.csdn.net/genedecoders/article/details/120682092)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文