SQL簡單明瞭的Case函式說明

2021-10-23 21:20:21 字數 728 閱讀 6874

case函式有點像if else 和 switch 語句的結合一樣的流程控制函式;

它end結束後會有返回值;

1,第一種是簡單函式:等值比較型

case 欄位名

when 字段值1 then 結果1

when 字段值2 then 結果2

else 結果3

end

比如下面判斷乙個人的性別,用***的值0表示女,1表示男,3表示陰陽人。

case ***

when

0then

"女"when

1then

"男"else

"陰陽人"

end

2,第二種是搜尋函式:判斷型

case 

when 條件1 then 結果1

when 條件2 then 結果2

else 結果3

end

比如下面的判斷乙個人的體重是不是正常,如果體重大於150偏重,小於90有點瘦,在90到150之間正常。

case

when height <

90then

"有點瘦"

when height >

150then

"胖了"

else

"正常"

end

簡單明瞭的SQL建立語句

1.建立資料庫sql語句 use master goif exists select from sysdatabases where name commonpermission begin select 該資料庫已存在 drop database commonpermission 如果該資料庫已經存...

簡單明瞭的SQL優化小技巧

總結一下就是為了提高效率,優化sql 是一種方式,索引的合理建立和使用也是一種方式。1,為了提高效率一般會使用索引,但是不好的sql 語句會使得資料庫放棄索引 而進行全表掃瞄 大大的降低效率 比如下面?這些 所以sql 語句要注意。1 一般使用 like 時,第乙個位置一定不能加上 如like 張 ...

最簡單明瞭的yield from解釋

def one print one start res yield from two print function get res res return one res deftwo print two start res yield from three print two1 return res...