两个SQL查询之间的不同值

发布于 2025-02-03 21:07:21 字数 897 浏览 2 评论 0原文

我希望能够找到一天对另一天的数据输入数据之间的任何潜在差异。

相关的col。从表中可以看到:

Name | Size | DateSale | Location | Comments | Date

两个当前查询是:

Select Name, Size, DateSale, Location, Comments from [Table] where Date = '06/02/2022'
Select Name, Size, DateSale, Location, Comments from [Table] where Date = '06/01/2022'

我将如何提出与这两个列表不同的值列表?尝试与Select Distion一起工作,但无法弄清楚。

示例数据:

 Name | Size | DateSale | Location | Comments | Date
 john | 100  |06/05/2022| Houston  | proj.    | 06/02/2022
 john | 100  |06/04/2022| Dallas   |          | 06/01/2022
 jake | 90   |06/04/2022| Houston  | proj.    | 06/02/2022
 jake | 90   |06/04/2022| Houston  | proj.    | 06/01/2022

所需结果:

 john | 100  |06/05/2022| Houston  | proj.    | 06/02/2022

由于键(名称 +大小)相同,但是其他类别(销售日期,位置或注释)也有差异,因此它将返回 第一个查询的行(最近日期)

I want to be able to find any potential differences between data inputted on one day to another.

The relevant col. from the table are seen below:

Name | Size | DateSale | Location | Comments | Date

The two current queries are:

Select Name, Size, DateSale, Location, Comments from [Table] where Date = '06/02/2022'
Select Name, Size, DateSale, Location, Comments from [Table] where Date = '06/01/2022'

How would I come up with a list of values that are different from these two lists? Tried working with select distinct but could not figure it out.

Sample Data:

 Name | Size | DateSale | Location | Comments | Date
 john | 100  |06/05/2022| Houston  | proj.    | 06/02/2022
 john | 100  |06/04/2022| Dallas   |          | 06/01/2022
 jake | 90   |06/04/2022| Houston  | proj.    | 06/02/2022
 jake | 90   |06/04/2022| Houston  | proj.    | 06/01/2022

Desired Result:

 john | 100  |06/05/2022| Houston  | proj.    | 06/02/2022

Since the keys (Name + Size) are the same, but there are differences in the other categories (Sale Date, Location, or Comments), it will return
the row from the first query (most recent date)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

成熟的代价 2025-02-10 21:07:21
SELECT y.* FROM (SELECT * from Table where Date = '05/31/2022') as x, 
(SELECT * FROM Table where DATE = '06/02/2022') as y where x.Name = y.Name 
and x.Size = y.Size and (x.DateSale!=y.DateSale or x.Location!=y.Location or 
x.COMMENTS != y.COMMENTS) 

这个解决方案对我有用

SELECT y.* FROM (SELECT * from Table where Date = '05/31/2022') as x, 
(SELECT * FROM Table where DATE = '06/02/2022') as y where x.Name = y.Name 
and x.Size = y.Size and (x.DateSale!=y.DateSale or x.Location!=y.Location or 
x.COMMENTS != y.COMMENTS) 

This solution worked for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文