当前位置:网站首页>Introduction and advanced MySQL (XIV)
Introduction and advanced MySQL (XIV)
2022-07-29 03:09:00 【Xiaoxinai programming】
Query result set as ⼀ Virtual tables directly participate in the query
Update send ⽤⼦ Inquire about : Can appear in set The position of the value can also appear where Conditional location
Eg: Those who fail will learn ⽣ Class changed to id most ⼤ In my class
Delete send ⽤⼦ Inquire about : Only in conditional positions
Eg: Delete all the score information of the lowest score
Eg: Delete all the score information of the lowest score :where Conditions can be written in subqueries , Modified delete query , however :mysql It does not support deleting or modifying a table while querying , Nesting a subquery can solve .
delete from exam where exam=(
select * from(select min(exam) from exam)a
-- Eg: Change the failing students' class to id In the largest class
-- Subqueries can be used as search conditions or as values
select max(classid) from class
select studentid from exam where exam<60
update studentinfo set classid=(select max(classid) from class)
where studentid in(
select studentid from exam where exam<60
)
adopt EXISTS lead ⼊ The existence of the test ⼦ Inquire about
with EXISTS The predicate ⼦ The query does not return any actual data
Only produce ⽣ Logical truth “true” Or logical false value “false
Eg: Inquire about C# The course exam is just equal to 60 Divided learning ⽣ list
EXISTS: His result set value is useless , Just judge whether there is a result set , If there is a result set, the peripheral query results, otherwise the peripheral query of this line will not be displayed .
Judge whether the result set has value , promising true No, false.
Execution order : The peripheral query of each row will judge the sub query inside , If the subquery has a result of true Not for false
If there are many peripheral queries , There are few sub queries exits It doesn't make much sense
If there is less peripheral data , There are many sub queries , here exits It's a lot more efficient
exitts Internal and external inquiries must be connected .
Eg: Inquire about C# The course exam is just equal to 60 A list of students
select subjectid from `subject` where subjectname=' be based on C Language understanding software
Programming '
select * from exam where exam=60 and subjectid=1
select * from studentinfo where studentid in(
select studentid from exam where exam=60 and subjectid=1
)
-- Students in every line , Use both id Go to exam Query in table , If the return value is recorded , So stupid students stay or don't show
select * from studentinfo a where EXISTS(
select * from exam b where exam=60 and subjectid=1 and
a.studentid =b.studentid)
边栏推荐
- 2022-07-28 第四小组 修身课 学习笔记(every day)
- Weekly recommended short videos: how to make product development more effective?
- MYSQL入门与进阶(十四)
- Engineering boy: under 20 years old, ordinary but not mediocre
- 三子棋(玩家+电脑)
- Feedback function of conference OA
- SAP 中国本地化内容汇总
- Look at robot education and lead the mainstream of quality education
- Shell script summary
- Principle knowledge is useful
猜你喜欢

Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.

会议OA之反馈功能

【C】数组

04 | 后台登录:基于账号密码的登录方式(上)

会议OA项目之我的审批功能

Navicat new database

Inventory of domestic and foreign project collaborative management software: SAAS and customization become a trend

Analysis of Project-based Learning Creativity in steam Education

Chapter 2 VRP command line

Engineering boy: under 20 years old, ordinary but not mediocre
随机推荐
【FreeSwitch开发实践】media bug获取通话语音流
Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.
shell脚本总结
navicat新建数据库
Why did I choose the test when the development salary was high?
年内首个“三连跌” 95号汽油回归“8元时代“
The basic concept of the origin and connotation of maker Education
MySQL - the difference between count (field), count (primary key), count (1), count (*)
原理知识用得上
算法---粉刷房子(Kotlin)
Alibaba Sentinel - 工作流程及原理解析
Hangao database best practice configuration tool Hg_ BP log collection content
Digital image processing Chapter 10 - image segmentation
C traps and defects Chapter 3 semantic "traps" 3.1 pointers and arrays
HTB-Blue
Chapter 09_ Use of performance analysis tools
C陷阱与缺陷 第3章 语义“陷阱” 3.3 作为参数的数组声明
VIM common commands
Verilog: blocking assignment and non blocking assignment
照片比例校正工具:DxO ViewPoint 3 直装版