50 Query Series-the third query: query all students of the student number, name, number of courses selected, total;

Source: Internet
Author: User

The main query is to determine the main table of the query, and the secondary table.

In this case we can confirm that it is a subquery.

The main table is our student table: Tblstudent can find the student's school number, name

The auxiliary table is the score table, Tblscore

Write your own statement as follows:

SELECTTblstudent. Stuid,tblstudent. Stuname,xuankeshu.kscount,kccj.countscore fromTblstudent, (SELECT  Count(Tblscore. CourseID) Kscount,tblscore. Stuid Sidd fromTblscoreGROUP  bytblscore.stuid) Xuankeshu,--The number of students selected is found here, grouped by student number(Select  sum(Tblscore. Score) Countscore,tblscore. Stuid siddd fromTblscoreGroup  bytblscore.stuid) KCCJ--The students ' total scores are identified here, grouped by student's numberwhereTblstudent. Stuid=Xuankeshu.sidd andTblstudent.stuid=Kccj.siddd

The answer is:

Select Stuid,stuname,  (SelectCountfromWhere t1.) Stuid=s1. Stuid) selcourses, (SelectSumfromWhere T2. Stuid=s1. STUID)  Sumscore    from tblstudent S1

Three select directly each one is a piece of data.

50 Query Series-the third query: query all students of the student number, name, number of courses selected, total;

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.