sql-test scores for each subject and the number of subjects involved

Source: Internet
Author: User

Check the students ' scores in each subject: (Statistics on the test scores of each subject)

Chart of Accounts:

Id:int primary key self-increment

Course:varchar len:20

Score Table:

ID int PRIMARY Key auto-increment

Name:varchar len:20

Score int

course_id int foreign key associated account table ID

The ID of the foreign key related account table and the course_id of the score table;

SQL as follows

SELECTt_score.name Name,SUM( CaseT_course.course when 'Mathematics'  ThenT_score. ScoreELSE 0 END) asMathematics,SUM( CaseT_course.course when 'language'  ThenT_score. ScoreELSE 0 END) aslanguage fromT_course,t_scoreWHERET_score. course_id=t_course.idGROUP  byName

Query Result:

Check the number of students in each subject: (count the number of exams per course)

There are a few more data on the score table:

Field definition as above

Query SQL as follows:

SELECTt_score.name Name,COUNT( CaseT_course.course when 'language'  ThenT_score. ScoreELSE NULL END) aslanguages,COUNT( CaseT_course.course when 'Mathematics'  ThenT_score. ScoreELSE NULL END) asMathematics fromT_course,t_scoreWHERET_score. course_id=t_course.idGROUP  byName

Query Result:

sql-test scores for each subject and the number of subjects involved

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.