当前位置:网站首页>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
边栏推荐
猜你喜欢

TP5 error reporting variable type error: array solution

压力测试工具 Jmeter

.Net Core3.1 使用 RazorEngine.NetCore 制作实体生成器 (MVC网页版)

Leak detection and vacancy filling (III)

Devexpress Gridview 添加全选列

FOC SVPWM function pwmc_ Setphasevoltage parsing

Kids and COVID: why young immune systems are still on top

Redux overview

微信小程序

leetcode刷题之二进制求和
随机推荐
SiteServer CMS5.0使用总结
sqlserver性能优化建议
微信小程序
JS性能优化
Promise(二)
百度地图基础案例
条形码与二维码的生成
Thinkphp5 -- object (think \ response \ JSON) to array
小米摄像头异常解决
el-cascader和el-select点击别处让下拉框消失
Analysis of fixed point PID code of FOC motor Library
file_ get_ Two solutions to content accessing SSL errors
1-5 NodeJS CommonJs规范
.Net Core 下使用 Quartz —— 【7】作业和触发器之简单触发器
Color string conversion
Router对象、Route对象、声明式导航、编程式导航
C# Dapper 基本使用 增删改查事务等
JS正则匹配先行断言和后行断言
SignalR实现从服务端主动发送数据到客户端
几款笔记软件的优缺点