找出两列:间的差异
问题说明
我不确定这个问题的标题是什么,但如果你有更好的主意,请随时编辑它.
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
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanghhcbi
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20