【问题标题】:Check records from same table with unmatched values in multiple rows based on date根据日期检查多行中具有不匹配值的同一表中的记录
【发布时间】:2018-09-18 09:21:26
【问题描述】:

我想从同一个表中选择不匹配的组合:

表 1

因此,根据上表,2018 年 9 月 15 日的 #Id 组合 (#3,#4,#5) 缺失,而 #Id 组合 (#8,#9,#10) 则完全不同2018 年 9 月 15 日与 2018 年 9 月 14 日相比。

所以我想选择这样的 ID [#Id 组合 (#8,#9,#10)] 并打印出来

如何通过查询找到这个?

【问题讨论】:

  • 这是一个很难理解的问题。您能否提供您期望的确切输出(最好以表格形式),我们可以从那里开始工作吗?

标签: sql-server sql-server-2008 sql-server-2012 sql-server-2008-r2


【解决方案1】:

当您说“组合 #8”时,您实际上只是指服务器 3 + 许可证 1?像这样?

declare @daycount int
select @daycount = count(distinct [date]) from table1

select ServerID, LicenseID
from table1
group by ServerID, LicenseID
having count(*) != @daycount

【讨论】:

    猜你喜欢
    • 2020-03-05
    • 2019-02-18
    • 2021-09-17
    • 2012-07-20
    • 1970-01-01
    • 2023-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多