1樓:傳說中的鷹王
simenyu 的正解。
直接用in肯定是不行的,比學生s2 選修的課程少的也會列出來用not exists 我也無法理解。
這段話:
select * from sc as sc2where s.sno=sc2.sno
and sc2.cno=sc1.cno
是與學生s2選修課程相同的 選課資訊
這段話:
select * from sc as sc1where sc1.sno='s2'
and not exists
(select * from sc as sc2where s.sno=sc2.sno
and sc2.cno=sc1.cno)
如果存在與s2選課相同的資訊,則查出結果為空。
如果不存在與s2選課相同的資訊,則查出結果s2的選課資訊。
最後總體這段話:
select sno,sname
form s
where not exists
(select * from sc as sc1where sc1.sno='s2'
and not exists
(select * from sc as sc2where s.sno=sc2.sno
and sc2.cno=sc1.cno) )如果存在與s2選課相同的資訊,則查出結果所有的學號、姓名資訊。
如果不存在與s2選課相同的資訊,則查出結果為空。
根本不符合題意。不知道是不是我理解錯誤
2樓:匿名使用者
將s2的學生所選修的課程都列出來,將其他學生選的課程名列出來,然後join一下
SQL連線查詢,sql 連線查詢跟多表查詢的區別
select a.name,substr max sys connect by path b.definition,2 prize from a,b,select rn,prize id,decode rn,1,0,instr prize,1,rn 1 1 sp,decode instr prize...
sql基礎查詢語句,sql簡單查詢語句
greate table insert selce filetad,name,calss,form student sql簡單查詢語句 1 首先開啟資料庫,建立好表。2 然後查詢全體教師的教師號 姓名 職稱,並分別為三列指定別名 教師號 姓名 職稱,如下圖所示。3 查詢結果如下圖所示。4 接著查詢所...
sql查詢部分欄位重複的記錄,sql查詢兩個欄位相同的記錄
加上日期限制 access select distinct setname setnum from table name where subtime between date and dateadd m 1,date sql server select distinct setname setnum...