SQL Common face question (Student table _ Schedule _ General table)

Source: Internet
Author: User

Description of the problem: for the management of post business training information, the establishment of 3 tables:

S (S#,SN,SD,SA) S#,sn,sd,sa respectively represents student number, student name, affiliation unit, student age

C (C#,CN) C#,CN represents the course number, the course name, respectively

SC (S#,C#,G) S#,c#,g respectively represents the student number, the selected course number, the academic achievement

The following 5 processes are required:

1. Use standard SQL nested statements to query the student number and name of the elective course named ' Tax base '--Implementation code:SELECTSn,sd fromSWHERE [s#] inch(    SELECT [s#]  fromC,SCWHEREC.[C #]=Sc.[C #]         andCN=N'Tax Base')2. Use standard SQL nested statements to query the student name and affiliation of the elective course number ' C2 '--Implementation code:SELECTS.sn,s.sd fromS,SCWHERES.[s#]=Sc.[s#]     andSc.[C #]='C2'3. Use standard SQL nested statements to query the name and affiliation of the participant who does not take the course number ' C5 '--Implementation code:SELECTSn,sd fromSWHERE [s#]  not inch(    SELECT [s#]  fromSCWHERE [C #]='C5')4. Use standard SQL nested statements to query the name and affiliation of the student taking all courses--Implementation code:SELECTSn,sd fromSWHERE [s#] inch(    SELECT [s#]  fromSC Right JOINC onSc.[C #]=C.[C #]    GROUP  by [s#]     having COUNT(*)=COUNT(DISTINCT [s#]))5. Query the number of participants who have enrolled in the course--Implementation code:SELECTNumber of trainees=COUNT(DISTINCT [s#]) fromSC6. Query elective courses more than 5 student number and affiliation unit--Implementation code:SELECTSn,sd fromSWHERE [s#] inch(    SELECT [s#]  fromSCGROUP  by [s#]     having COUNT(DISTINCT [C #])>5)

SQL Common face question (Student table _ Schedule _ General table)

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.