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)