Related subqueries "SQL Server"

Source: Internet
Author: User

Inquire about books in book tables that are larger than the average price of such books

First record the class number of the value of 2 into the subquery, the subquery is

Select AVG (Price)

From book B

where b.id=2

The average price for a book with class number 2 is (23+45)/2=34

and make judgments with external queries.

SELECT * FROM Book a

where price>34

And then class number 3 in the book again by comparing

Correlated subqueries (multi-valued subqueries)

1. A non-correlated subquery (nested subquery) is an external subquery that executes only once, the query can be executed multiple times, and the value is passed to the external query after execution.

2. In the related subquery, the outer query executes once, and the subquery executes once

Related subqueries "SQL Server"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.