作者adoniscomes (adonis)
看板Database
標題[SQL ] 尋找特定欄位為Null之組別
時間Wed May 16 15:58:49 2018
資料庫名稱: Oracle + PL-SQL
內容/問題描述:
學生Table stb 組別對應Table sTeam
學生編號 畢業年月 組別 學生編號
sno ym tno sno
01 10704 1 01
02 1 02
03 10703 1 03
04 10701 2 04
05 10701 2 05
06 10701 2 06
07 3 07
08 3 08
09 3 09
10 10701 4 10
11 10702 4 11
12 10703 4 12
想要列出 『每個ym欄位均不為null』之組別:
tno
2
4
目前想法寫法是
Select s2.tno
From stb s1, sTeam s2
Where s1.sno = s2.sno
And s1.ym is null
Group by s2.tno
Having count(s.sno) = 0
但出來的結果似乎不太對...
有想到Not exist的方向但因為不熟所以不知道從何下手..
來這邊請教眾大神指導幫忙 感謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 210.71.217.243
※ 文章網址: https://www.ptt.cc/bbs/Database/M.1526457533.A.DC8.html
推 adrianshum: Select distinct t.tno from steam t where not exist 05/17 20:02
→ adrianshum: (select 1 from steam t1 inner join stb s1 on s1.s 05/17 20:02
→ adrianshum: no=t1.sno where t1.tno =t.tno and s1.ymd is null) 05/17 20:02