current position:Home>Hive -- about case when

Hive -- about case when

2022-02-04 16:58:53 CSDN Q & A

Pictured
case when I always thought that only this form is commonly used
#1-----------------------------------

SELECT epc.id,case when epc.epc_type='1' then '1 Emergency price change of fresh food '         when epc.epc_type='2' then '2 Poster error correction '          end as epc_type,epc.form_flag,epc.convenience_flag,lst.cmmdty_code gds_cd,lst.cmmdty_name,

** Today I see another form **
#2-----------------------------------

SELECT epc.id,case when epc.epc_type='1' then '1 Emergency price change of fresh food ' elsecase when epc.epc_type='2' then '2 Poster error correction ' end end epc_type,epc.form_flag,epc.convenience_flag,lst.cmmdty_code gds_cd,lst.cmmdty_name,

There are a few questions
1、 Is the result of these two ways of writing the same , What's the difference ??
2、 When will I use the second way
3、 Every case when Statements in end You need to write an alias after , that #2 Because there are 2 individual case, So there is 2 individual end, But only one alias was written ..

case when

img




Take the answer :

This is a case when then Nesting of , the second case Written in the first case Of else It's just inside
Follow if set if Same, same


copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/02/202202041658512526.html

Random recommended