Group the first n SQL statements !!!

Source: Internet
Author: User

 

Table Structure:


Student ID class Chinese score
1 1 21
2 1 1
3 1 3
4 1 324
5 1 54
6 1 54
7 1 47
8 1 45
9 1 32
10 1 323
11 1 23
12 1 5
13 1 345
14 2 34
15 2 5
16 2 44563
17 2 345
18 2 234
19 2 234
20 2 345
21 2 12
22 2 12
23 2 31
24 2 534
25 2 67
26 2 567
27 2 856
28 2 732
29 2 23
30 3 32
31 3 46
32 3 45
33 3 234
34 3 7
35 3 567
36 3 3
37 3 634
38 3 64
39 3 2
40 3 23
41 3 23
42 3 523
43 3 4
44 3 3
45 3 5324


Query results:

Student ID class Chinese score
4 1 324
13 1 345
16 2 44563
27 2 856
37 3 634
45 3 5324


Requirement: retrieve the first two records of all classes:


Select *

From table as

Where language score in (select Top 2 Language score from table where class = A. class order by language score DESC)

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.