Comfortable, is left to the dead! Only 1W away from the comfort of the day! These tired don't want to live SQL query!

Source: Internet
Author: User

Kindergarten class, Silent

Attention:

The following code is simple and easy to understand please watch carefully!

The average score of each course is queried and sorted in descending order

1 Select Gradeid,SUM as  Total number of hours 2 from Subject3Group  by Gradeid 4 Order  by sum (Classhour)

2--check the average score for each participant in the exam

1 Select studentno,AVG as draw score 2 from Result3  Group by Studentno

3--the average score for each course and in descending order

1 Select subjectid,avg(studentresult) as average score 2 from Result3Group by subjectid4orderby  desc

4--Check the total score for each student in all exams and arrange them in descending order

1 Select Studentno,SUM as  total 2 from Result3 Group  by Studentno 4 Order  by desc

Two

Find out the number of courses with more than 50 per year of class hours S1

1 Select Gradeid,count  as course number 2 from Subject3 where  Classhour>4Group by Gradeid

2--Check the average age of each grade student:

1 Select Gradeid,avg(DATEDIFF(yy,birthday,GETDATE as average age  2 from student3Group by

3--inquiry for students in each grade including Beijing

1 Select Gradeid,COUNT(1 as total number 2 from student 3 where  like ' % BEIJING% ' 4 Group  by Gradeid

4--for students who have taken the exam, the average number of students who have passed the test (student, average), in descending order

1 SelectStudentno,AVG(Studentresult) asAverage score2  fromResult3 Group  byStudentno4  having AVG(Studentresult)>= -5 Order  byAverage scoredesc 

5--examination time is the average pass of the 2009-9-9 course

1 SelectSubjectid,AVG(Studentresult) asAverage score2  fromResult3 whereExamdate>='2009-9-9'  andExamdate<'2009-9-10'4 Group  bySubjectid5  having AVG(Studentresult)>= -

6--statistics at least one failed student number and number.

1 Select studentno,Count(1 as   times 2 from Result  3where studentresult<4Groupby Studentno

Friends sharing ends here

Please wait for the next share

                          

Comfortable, is left to the dead! Only 1W away from the comfort of the day! These tired don't want to live SQL query!

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.