一道sql面試題
數據庫有3個表 teacher表 student表 tea_stu關係表
teacher表 teaID name age
student表 stuID name age
teacher_student表 teaID stuID
要求用一條sql查詢出這樣的結果:
1.顯示的字段要有老師id age 每個老師所帶的學生人數
2.只列出老師age爲40以下 學生age爲12以上的記錄
結果sql,在db2測試成功:
select a.teaId,a.age,count(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
teacher表 teaID name age
student表 stuID name age
teacher_student表 teaID stuID
要求用一條sql查詢出這樣的結果:
1.顯示的字段要有老師id age 每個老師所帶的學生人數
2.只列出老師age爲40以下 學生age爲12以上的記錄
結果sql,在db2測試成功:
select a.teaId,a.age,count(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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
24-5-18 X
Higurashi-kagome
2024-06-01 14:30:43
【dubbo】如何測試一個dubbo服務呢?
金大鑫要堅持
2024-06-01 14:29:53
kubeconfig 多個集羣配置 如何切換
kubectl config get-contexts kubectl config use-context <context-name> kubectl config current-context
hiningrise
2024-06-01 14:27:53
兩臺windowserver服務器配置Redis哨兵集羣
天才臥龍
2024-06-01 14:24:12
oidc-client.js踩坑吐槽貼
提伯斯
2024-06-01 14:23:02
微盟電商-以造數工廠爲底座的低成本自動化應用實現(一)
保軍Baojun
2024-06-01 14:20:12
Mac Brew install慢的問題
阿 軍
2024-06-01 14:18:02
Vue devDependencies 與 dependencies 能別
阿 軍
2024-06-01 14:18:02
mysql 超大大數據庫複製前可執行的加速導入的SQL
菊花茶
2024-06-01 14:14:21
css25 CSS Tables
emanlee
2024-06-01 14:13:21
css29 CSS Layout - The z-index Property
emanlee
2024-06-01 14:13:21
css28 CSS Layout - The position Property
emanlee
2024-06-01 14:13:21
css26 CSS Layout - The display Property
emanlee
2024-06-01 14:13:21
css31 CSS Layout - float and clear
emanlee
2024-06-01 14:13:21