当前位置:网站首页>Subqueries in sqlserver
Subqueries in sqlserver
2022-06-22 06:06:00 【L_ ZWge】
- Subquery
A subquery is nested in another statement ( Such as :[SELECT],[INSERT],[UPDATE] or [DELETE]) Query in , It is an application of grammar .
We might as well understand it through examples , The following statement shows how to SELECT Of the statement [WHERE] Clause to find the location in New York ( New York ) Customer's sales order :

- nested subqueries
Nested subquery means that one subquery can be nested in another subquery .
stay SQL Server in , Most support 32 Nested levels .
give an example : Find a price higher than “ Shanghai forever ” and “ Phoenix ” The average price of all products of the brand .
For such questions , We need to examine the subject , And make it clear which one needs to be queried in the end ,
First step , First name the brand “ Shanghai forever ” and “ Phoenix ” Of id obtain

The second step , Calculate the average price of all products belonging to two brands

The third step , Use nested subqueries to set prices above “ Shanghai forever ” and “ Phoenix ” The average price of all the products of the brand can be found

Use nested subqueries to simplify query statements and avoid tedious repetition , Is it convenient . The results will not be shown here , You can also try to operate it .
- Correlation subquery
Related subqueries use the values of external queries [ Subquery ]. let me put it another way , It depends on the value of the external query .
Because of this dependency , Related subqueries cannot be executed independently as simple subqueries . Besides , Repeat the related sub query for each row of the external query evaluation . therefore , Related subqueries are also called duplicate subqueries .
give an example : Find a product whose price is equal to the highest price of its category .

- Exists Operator
- EXISTS The operator is a logical operator , Used to check whether the subquery returns any rows . If the subquery returns one or more rows , be EXISTS Operator return TRUE .
- Here are SQL Server EXISTS The syntax of the operator :

In this grammar , The subquery is just SELECT sentence . After the sub query returns rows , EXISTS Operator return TRUE And immediately stop processing . Please note that , Even if the subquery returns NULL value , EXISTS The operator also evaluates to TRUE
- With query EXISTS return NULL Example
give an example : The following example returns customers All the rows in the table :

In this example , The subquery returns a query containing NULL The result set , This has also led to EXISTS Operator evaluates to TRUE .
Okay , Let's share today !
边栏推荐
- 从转载阿里开源项目 Egg.js 技术文档引发的“版权纠纷”,看宽松的 MIT 许可该如何用?
- Logback自定义Pattern参数解析
- Unity development - scene asynchronous loading
- 关于MNIST线性模型矩阵顺序问题
- 单细胞文献学习(part2)--stPlus: a reference-based method for the accurate enhancement of ST
- C指針的理解
- 小熊派BearPi-HM Micro正式合入OpenHarmony主干
- Unity 加密ASE 游戏数据
- 生信可视化(part3)--小提琴图
- R语言观察日志(part24)--writexl包
猜你喜欢

SSM整合所需配置文件及常见配置错误引起的报错

活动预告|EdgeX 开发者峰会@南京站 来啦!

单细胞论文记录(part9)--Spatial charting of single-cell transcriptomes in tissues

经验模式分解(EMD)和希尔伯特-黄变换(HHT)

Simple use of idea plug-in easy code

Frame profiling

单细胞文献学习(part3)--DSTG: deconvoluting spatial transcriptomics data through graph-based AI

从入门到精通之专家系统CLIPS(一)CLIPS初识与概述

Ptrade trading program code - from zero to firm offer 19

单细胞论文记录(part12)--Unsupervised Spatial Embedded Deep Representation of Spatial Transcriptomics
随机推荐
An unordered array of N integers. Find the first number after each element that is larger than it. The time complexity is O (n)
【Rust笔记】04-表达式
System identification of automatic control principle
D3D10 screenshot function saves texture to local
机器学习概念梳理(无公式)
Design input of Oracle project management system
MYSQL牛客刷题
Unity development - scene asynchronous loading
idea插件Easy Code的简单使用
C#中的数组及Foreach遍历
从转载阿里开源项目 Egg.js 技术文档引发的“版权纠纷”,看宽松的 MIT 许可该如何用?
不务正业系列7:老照片去除斑点手法
Test platform for combinational logic blocks
402 string (Title: Sword finger offer58 ii. left rotation string, 28. implementation of strstr(), 459 Repeated substrings)
Creating GLSL Shaders at Runtime in Unity3D
牛客-TOP101-BM27
【雲計算重點複習】
400 hash table (1. sum of two numbers, 454. sum of four numbers II, 383. ransom letter)
单细胞论文记录(part10)--Computational challenges and opportunities in SRT data
Logback自定义Pattern参数解析