A SQL interview question

xiaoxiao2021-03-06  43

The database has 3 tables Teacher Table Student Table Tea_stu Relational Table

Teacher Table Teaid Name Age

Student Table Stuid Name Age

Teacher_Student Table Teaid Stuid

Requires an SQL to query this result:

1. The displayed field must have the number of students that the teacher ID AGE

2. Only the record of the teacher agn is 40 or less of the student AGE is more than 12

Result SQL, success in DB2 test:

Select A.Teaid, A.TEAID (B.STUID) from Teacher A Join Tea_Stu B on a.teaid = B.Teaid Join Student C on B.Stuid = C.Stuid and C.AGE> 12 Group by a. Teaid, A.AGE Having A.age <40

转载请注明原文地址:https://www.9cbs.com/read-57307.html

New Post(0)