iT邦幫忙

2

SQL語法問題。從B表單的複數欄位作為條件,去篩選掉A表單的幾筆資料。

A表單為主要表單
內有year、month、place、dataA1、dataA2、dataA3...等欄位

B表單主要記錄一些例外狀況的資料
內有year、month、place、dataB1、dataB2...等欄位

兩個表單的資料不相同,但year、month、place可相互對應

現在若想要篩去A表單中year、month、place與B表單year、month、place"同時符合"的資料,只保留A表單中非例外資料的內容的話,請問SQL查詢語法要怎麼下呢?感謝

用delete from a where xxx not in (select xxx from b )
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

2
純真的人
iT邦大師 1 級 ‧ 2022-08-04 15:01:02
最佳解答

就用Exists

select *
from a
where not Exists(
	select 0
	from b
	where a.year = b.year
	and a.month = b.month
	and a.place = b.place
)
lsesroom iT邦新手 3 級 ‧ 2022-08-04 15:15:32 檢舉

感謝!解決問題了

我要發表回答

立即登入回答