簡體   English   中英

比較兩個表中的列並創建一個SQL視圖

[英]Compare columns in two tables and create a SQL view

我有兩個表,數據存儲在兩個表中

TabelA

cert_id  custid
-----------------
  002    C1
  003    C1
  004    C1
  005    C1
  006    C1
  007    C2
  008    C2
  009    C2
  010    C2

表B

cert_id                 custid
-------------------------------
002, 003, 004           C1
008, 010                C2

我正在嘗試在TableB( cert_id )中尋找相同數據的地方創建一個數據,如果在列中匹配,則不應在視圖中。

在上面的示例中,列中的cert_id均應與其他表進行比較,然后列出不在TableB中的那些

因此,新視圖應顯示如下內容:

視圖1

cert_ids
--------
005
006
007
009
select a.cert_id from tablea a inner join tableb b 
on b.cert_id not like'%'+ a.cert_id  +'%' 
and a.custid=b.custid

http://sqlfiddle.com/#!6/2c90dc/1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM