SQL advanced query: nesting and Paging

Source: Internet
Author: User

1. Nested subqueries

--Check for students who have not taken the exam in the most recent OOP exam
SelectStudentname fromStudentwhereStudentno not inch(SelectStudentno fromResultwhereSubjectid=(SelectSubjectid fromSubjectwhereSubjectname='OOP') andExamdate=(Select MAX(examdate) fromResultwhereSubjectid=(SelectSubjectid fromSubjectwhereSubjectname='OOP' ) ))

2. Related sub-query

SElECT Name,id,price    from  as C   WHERE  Price>  (    SELECTAVG    . From  as  a    WHERE C. class number =A. Class number  )

3. Paging Query

The first type:

 --  Skip the five lines and take two rows   top  2  *  from   Student  where  Studentno not  in   ( select   Top  5  studentno from   Student  order  by   Studentno)  order  by  Studentno 

The second type:

-- take line fourth to line sixth Select *  from (Select*over (orderby as as tempwherebetween4and6

SQL advanced query: nesting and Paging

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.