問題描述
我不確定這個問題的標題是什么,但如果你有更好的主意,請隨時編輯它.
I wasn't sure what to title this question, but feel free to edit it if you have a better idea.
假設我有如下所示的數據:
Let's say I have data that looks like this:
Column A Column B
John, Sally, Cindy John, Sally, Cindy, Steve
John, Cindy John, Sally, Cindy
Sally, Cindy Sally, Cindy
Sally, Steve John, Sally, Steve
我想做的是找出差異.我想查看 column B
中存在哪些不在 column A
中的內容,以便我有一列如下所示:
What I would like to do is find the differences. I want to see what exists in column B
that are not in column A
, so that I have a column that looks like this:
Column C
Steve
Sally
''
John
對此有什么建議嗎?
編輯 #1:
表格不是這樣存儲的,表格每個單元格沒有多個值;但是,我從 SQL 查詢發送報告,任務是顯示 列 a 和 b
具有多個這樣的值的差異.
The table is not stored like this, the table does not have multiple values per cell; however, I am sending a report from a SQL query and the assignment is to show the differences with columns a and b
having multiple values like this.
這是我的 SQL 查詢目前在結果中的樣子.
This is what my SQL query currently looks like in the results so far.
編輯 #2:
表格中的每個記錄/列交叉點沒有多個值.為了讓最終用戶更容易查看報告,我在交集中放置了多個值,在我的 SQL 查詢結果中,以便顯示存在和不存在的內容.
There are not multiple values per record/column intersection in the table. To make the report easier to view for the end user, I placed multiple values in the intersection, in my SQL Query Results, so show what is there and what is not there.
我正在嘗試創建 column C
以顯示差異.
I am trying to create column C
to show the differences.
編輯 #3:
Column A
來自一個數據源Column B
來自另一個數據源.
Column A
comes from one data source
Column B
comes from another data source.
A 和 B 不是彼此的子集,我只是選取 2 列并嘗試以更簡單的方式找出差異.
A and B are not subsets of each other, I am simply taking 2 columns and trying to find the differences in an easier way.
推薦答案
不清楚是否要將多個差異聚合到一個分隔單元格中.
Not clear if you want multiple differences aggregated into one delimited cell.
示例
Declare @YourTable table (ColA varchar(150),ColB varchar(150))
Insert Into @YourTable values
('John, Sally, Cindy','John, Sally, Cindy, Steve'),
('John, Cindy','John, Sally, Cindy'),
('Sally, Cindy','Sally, Cindy'),
('Sally, Steve','John, Sally, Steve')
Select A.*
,B.*
From @YourTable A
Outer Apply (
Select Diff=value
From (
Select value=ltrim(rtrim(value)) From string_split(ColA,',')
Union All
Select value=ltrim(rtrim(value)) From string_split(ColB,',')
) B1
Group By Value
Having count(*)=1
) B
退貨
ColA ColB Diff
John, Sally, Cindy John, Sally, Cindy, Steve Steve
John, Cindy John, Sally, Cindy Sally
Sally, Cindy Sally, Cindy
Sally, Steve John, Sally, Steve John
這篇關于找出兩列之間的差異的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!