SQL limit T and rank over

Source: Internet
Author: User

1. How to Select 200th to 300th records from the table

Select top 300 * from table

Except

Select top 200 * from table

 

2. A table records the student's score a (studentname, grade) in a certain subject. The table is sorted by score and the column "rank" is added )". How to Write a query statement?

Select a. Name, A. grade,

Rank () over (order by grade DESC) rank

From DBO. STUDENT

Dense_rank () is also available. This indicates that when there is a parallel ranking, the next ranking will only increase by 1. For example, if there are two parallel ones, the score of 2nd is 2nd, not 3rd.

 

3. Suppose that in question 2nd, this table records the records of all students in different courses (studentname, coursename, grade), and groups and places the records by course. The query statement can be written in this way.

Select a. Name, A. Course, A. grade,

Rank () over (partition by course order by grade DESC) rank

From DBO. STUDENT

 

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.