当前位置:网站首页>The usage of case when and select case when is very easy to use
The usage of case when and select case when is very easy to use
2022-04-23 02:45:00 【Mechanical bucket running】
Case There are two formats . Simple Case Functions and Case The search function .
Simple Case function
CASE sex
WHEN ‘1’ THEN ‘ male ’
WHEN ‘2’ THEN ‘ Woman ’
ELSE ‘ other ’ END
–Case The search function
CASE WHEN sex = ‘1’ THEN ‘ male ’
WHEN sex = ‘2’ THEN ‘ Woman ’
ELSE ‘ other ’ END
Ways of planting , Can achieve the same function . Simple Case The writing of function is relatively simple , But and Case Search function , There will be some functional limitations , For example, write judgment . There is another problem that needs attention ,Case Function returns only the first value that matches the condition , The rest Case Parts will be automatically ignored .
– for instance , The following paragraph SQL, You'll never get “ The second category ” This result
CASE WHEN col_1 IN ( 'a', 'b') THEN ' The first category '
WHEN col_1 IN ('a') THEN ' The second category '
ELSE' other ' END
There are scores score,score<60 Return to fail ,score>=60 Return to pass ,score>=80 Return to excellence
SELECT
STUDENT_NAME,
(CASE WHEN score < 60 THEN ' fail, '
WHEN score >= 60 AND score < 80 THEN ' pass '
WHEN score >= 80 THEN ' good '
ELSE ' abnormal ' END) AS REMARK
FROM
TABLE
That's all for simple use , similar if function .
版权声明
本文为[Mechanical bucket running]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220745203374.html
边栏推荐
- hack the box optimum靶机
- 1215_ Hello world used by scons
- Leetcode cooking
- 解决win7 中powershell挖矿占用CPU100%
- Six very 6 computer driver managers: what software is good for driver upgrade? Recommended by the best computer driver management software abroad
- JZ22 鏈錶中倒數最後k個結點
- Practice of industrial defect detection project (III) -- Based on FPN_ PCB defect detection of tensorflow
- The 16th day of sprint to the big factory, noip popularization Group Three Kingdoms game
- Slave should be able to synchronize with the master in tests/integration/replication-psync. tcl
- Fashion MNIST 数据集分类训练
猜你喜欢
php+mysql對下拉框搜索的內容修改
双亲委派模型【理解】
After idea is successfully connected to H2 database, there are no sub files
How to prevent leakage of operation and maintenance data
Fashion MNIST dataset classification training
Log cutting - build a remote log collection server
JVM类加载器
How to solve the complexity of project document management?
Using go language to build web server
How to build an integrated industrial Internet plus hazardous safety production management platform?
随机推荐
MySQL复杂查询使用临时表/with as(类似表变量)
Slave should be able to synchronize with the master in tests/integration/replication-psync.tcl
Devil cold rice 𞓜 078 devil answers the market in Shanghai and Nanjing; Communication and guidance; Winning the country and killing and screening; The purpose of making money; Change other people's op
windows MySQL8 zip安装
谷雨
Go语言web中间件的使用
Using go language to build web server
The interface request takes too long. Jstack observes the lock holding
Learn regular expression options, assertions
Flink stream processing engine system learning (I)
程序设计天梯赛 L1-49 天梯赛分配座位(模拟),布响丸辣
Fashion MNIST 数据集分类训练
十六、异常检测
JZ76 删除链表中重复的结点
Flink learning (XI) watermark
MySQL complex query uses temporary table / with as (similar to table variable)
Understanding process (multithreading primary)
牛客手速月赛 48 C(差分都玩不明白了属于是)
TypeScript(1)
工业互联网+危化安全生产综合管理平台怎样建