当前位置:网站首页>SQL Server 2016 learning record - nested query
SQL Server 2016 learning record - nested query
2022-07-28 10:36:00 【Hard work Zhang Zhang】
Learning goals :
One 、 The basic concept of nested query
Two 、 Classification of nested queries ( Predicate classification )
1、 with IN Subquery of predicate
2、 Subqueries with comparison operators
3、 with ANY or ALL Subquery of predicate
4、 with EXISTS Subquery of predicate
Learning content :
One 、 The basic concept of nested query
Query block : One select The statement becomes a query block
nested queries : Nesting a query block in the... Of another query block where Clause or having Query in the condition of phrase 

Restrictions on subqueries :
Two 、 Classification of nested queries ( Predicate classification )
1、 with IN Subquery of predicate
Between parent query and child query IN Connect , The subquery result is a collection
-- Query and “ Liu Chen ” Students in the same department
--1. determine “ Liu Chen ” Family name
--2. Find all in IS Students in the Department
select sno,sname,sdept from student
where sdept In
(select sdept from student
where sname=' Liu Chen ');

Use self connection to realize the above question :
select s1.sno,s1.sname,s1.sdept from student s1,student s2
where s1.sdept=s2.sdept and s2.sname=' Liu Chen ';
-- Query the elective course named “ The information system ” Student ID and name of
select sno,sname from student
where sno In
(select sno from sc
where cno In
(select cno from course
where cname=' The information system ')
);

2、 Subqueries with comparison operators
Scope of application : When you know exactly that the inner query returns a single value , Available comparison operators and ANY or ALL Predicates are used in conjunction with
-- Find out the course number that each student has exceeded the average score of his elective course
select sno,cno from sc x
where grade >
(select avg(grade) from sc y
where y.sno=x.sno);
-- perhaps The inner layer can not be aliased
select sno,cno from sc x
where grade >
(select avg(grade) from sc
where sno=x.sno);

The subquery must follow the comparison character
3、 with ANY or ALL Subquery of predicate
ANY Any value
ALL All worth
-- Query the ratio of other systems IS Student number and name of all students in the Department who are older
select sname,sage from student
where sage > ALL
(select sage from student
where sdept='IS');

4、 with EXISTS Subquery of predicate
with EXISTS The subquery of the predicate does not return any actual data , He only produces logical truth ‘true’, Or a logical false value ‘false’
-- Query all non elective courses 1 Student name of course No
select * from student s;
select * from sc;
select sname from student s
where not exists
(select * from sc
where s.sno=sno and cno=1);

-- Check the names of the students who have taken all the courses
select sname from student s
where not exists
(select * from course c
where not exists
(select * from sc
where s.sno=sno and c.cno=cno));
边栏推荐
- QT generation Exe file and run without QT environment (enigma virtual box for green executable software packaging) graphic tutorial
- 传全球半导体设备巨头或将于上海建合资工厂!
- C language secondary pointer explanation and example code
- 287. Find the Duplicate Number
- [application of stack] - infix expression to suffix expression
- ACM winter vacation training 4
- ACM寒假集训#6
- Problem summary file
- Pl/sql server syntax explanation
- SDUT 2446 最终排名
猜你喜欢

QT generation Exe file and run without QT environment (enigma virtual box for green executable software packaging) graphic tutorial

Sword finger offer

CentOS7下安装mysql5.7

Chapter 1: cross end development of small programs of uniapp ----- create a uniapp project
![[wechat applet] project practice - lottery application](/img/7b/a0545f077259b3dc971dc246813177.png)
[wechat applet] project practice - lottery application

SQL Server 2016 learning records - single table query

机器学习--手写英文字母3--工程特点
![[application of stack] - infix expression to suffix expression](/img/c1/879716342f6dd5eaa8b79c752eca16.png)
[application of stack] - infix expression to suffix expression
![Database security - create login user + configure permissions [notes]](/img/02/0c3eb542593e8e0a3a62db75c52850.png)
Database security - create login user + configure permissions [notes]

AP Autosar平台设计 1-2 导言、技术范围与方法
随机推荐
多线程与高并发(三)—— 源码解析 AQS 原理
字符串匹配
ACM寒假集训#7
Can kingbasees v8r6 JDBC use VIP?
Vulnerability analysis hevd-0x8.integeroverflow[win7x86]
IDEA创建我的第一个项目
[wechat applet] project practice - lottery application
吴雄昂遭Arm罢免内幕:建私人投资公司,损害了股东利益?
Install Office customization. Troubleshooting during installation
Sword finger offer
6. Double pointer -- the sum of the two numbers of the incremental array is equal to the target number
2. Output one of the repeated numbers in the array
Aqua Data Studio 18.5.0 export insert statement
ACM winter vacation training 6
UEditor V1.4.3控制文件压缩
华为入股石墨烯材料厂商富烯科技,持股10%
The IPO of SMIC International Technology Innovation Board passed smoothly, and its market value is expected to exceed 200billion!
SQL Server 2016 学习记录 --- 数据定义
Excel word 简单 技巧 整理(持续更新 大概~)
Detailed explanation of super complete knowledge points of instruction system