当前位置:网站首页>Usage of if conditional statements in SQL
Usage of if conditional statements in SQL
2022-04-23 06:52:00 【Collect and study by yourself】
IF expression
IF( expr1 , expr2 , expr3 )
expr1 The value of is TRUE, The return value is expr2
expr1 The value of is FALSE, The return value is expr3
as follows :
SELECT IF(TRUE,1+1,1+2);
-> 2
SELECT IF(FALSE,1+1,1+2);
-> 3
SELECT IF(STRCMP("111","222")," It's not equal "," equal ");
-> It's not equal
So this IF What's the use ? for instance :
Find a sale price of 50 The book of , If it is java The words of the book , You have to label it as It's sold out
So the corresponding SQL How to write a sentence ?
select *,if(book_name='java',' It's sold out ',' In stock ') as product_status from book where price =50
IFNULL expression
IFNULL( expr1 , expr2 )
stay expr1 The value of the NULL
All cases return expr1, Otherwise return to expr2, as follows :
SELECT IFNULL(NULL,"11");
-> 11
SELECT IFNULL("00","11");
-> 00
from https://blog.csdn.net/zjq_1314520/article/details/62467086
版权声明
本文为[Collect and study by yourself]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555552021.html
边栏推荐
猜你喜欢
JS性能优化
ASP.NET CORE 依赖注入服务生命周期
.Net Core 下使用 Quartz —— 【3】作业和触发器之作业传参
.Net Core3.1 使用 RazorEngine.NetCore 制作实体生成器 (MVC网页版)
.Net Core 下使用 Quartz —— 【5】作业和触发器之触发器的通用属性和优先级
Leetcode刷题之实现strStr()
【ES6】 Promise相关(事件循环,宏/微任务,promise,await/await)
Analysis of fixed point PID code of FOC motor Library
Kids and COVID: why young immune systems are still on top
深入理解控制反转和依赖注入
随机推荐
Leak detection and vacancy filling (IV)
最近编程中遇到的一些问题2021/9/8
WebSocket(基础)
Node accesses server-side static resources
js查找字符串中出现了三次的字符
深入理解控制反转和依赖注入
Aperçu de Redux
常用sql语句收藏
Scientists say Australian plan to cull up to 10,000 wild horses doesn’t go far enough
TP6 的 each 遍历用法
Mailbox string judgment
【正河源刀具相关】
【Markdown笔记】
Method of MySQL password expiration
mysql中sum (if)_mysql 中sum (if())
.NET Standard详解
sql中的 IF 条件语句的用法
Arm common assembly instructions
五个路由守卫的使用
数据可视化百度地图进一步优化