Query maximum All column information after SQL grouping

Source: Internet
Author: User

CREATE TABLE Students (course varchar), Stu_name varchar (TEN), City varchar (ten), score int INSERT into students values (' math ', ' Jack ', ' Tianjin ', ' n '), insert into students values (' math ', ' Jordan ', ' Tianjin ', 80); INSERT into students values (' math ', ' James ', ' Beijing ', ' n '), insert into students values (' English ', ' Jack ', ' Tianjin ', ' n '); insert into students values (' English ', ' Jordan ', ' Tianjin ', max), insert into students values (' English ', ' James ', ' Beijing ', ' n '); INSERT into Students values (' language ', ' Jack ', ' Tianjin ', ' Max '), insert into students values (' language ', ' Tom ', ' Tianjin ', ' n '); INSERT INTO students VALUES (' Language ', ' Jordan ', ' Tianjin ', ' Studentsselect ');D elete from the students--when the maximum is multiple, take a SELECT * FROM (Selec        T Course,stu_name,city,score,row_number () over (partition by course ORDER BY score Desc) as RN from students  ) A WHERE A.rn <=1; --Maximum is more than one time to take select--a.course,a.score,b.stu_name,b.city,b.course course1,b.score score1 b.*from (select Course,max ( Score) score from students GRoup by course) Aleft joinstudents b ona.course=b.course and A.score=b.score; 

  

Query maximum All column information after SQL grouping

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.