【问题标题】:SQL SELECT all datasets where none of them match a criteriaSQL SELECT所有数据集都不符合条件
【发布时间】:2020-05-19 14:34:49
【问题描述】:

我想知道我是否可以从 Log Parser 数据库中请求以下条件。 (是的,没有两个数据库是很糟糕的,但就是这样。)

方案:

+-------------------------------------+
|  RegKey   |  Hostname | WinVersion  |
+-----------+-----------+-------------+
|  Regkey1  |   PC1     |    1909     |
|  Regkey2  |   PC1     |    1909     |
|  Regkey3  |   PC1     |    1909     |
|  Regkey1  |   PC2     |    1803     |
|  Regkey1  |   PC3     |    1909     |
|  Regkey2  |   PC3     |    1909     |
+-------------------------------------+

Hostname 和 WinVersion 确实适合每个数据集,但每个 regkey 都有自己的数据集。 我正在寻找的是列出或计数的语句,例如所有数据集都没有的所有主机名(RegKey LIKE RegKey3)。 因此,它会生成缺少 RegKey3 的所有主机名的列表。

当我使用 WHERE 和 GROUP BY 时,我当然会得到所有主机名,因为只过滤了 RegKey3 数据集。但这甚至可能吗? 我尝试使用 HAVING,但这似乎只对计数或数字比较有效。

谢谢!

妮可

【问题讨论】:

  • 用您正在使用的数据库标记您的问题。

标签: sql select logparser


【解决方案1】:

你可以使用:

select hostname
from t
group by hostname
having sum(case when RegKey LIKE RegKey3 then 1 else 0 end) = 0;

你可以试试这个替代方案:

select distinct hostname
from t
where not exists (select 1 from t t2 where t2.hostname = t.hostname and t2.RegKey like RegKey3);

【讨论】:

  • 嗨,戈登,哇,真快,非常感谢!不幸的是,Log Parser 似乎不支持“have”的这种组合:解析查询错误:语法错误:: not a valid
  • 实际上,LogParser 确实 支持 HAVING - 可能它不支持这种形式的 CASE 语句。你能提供你得到的确切错误吗?
  • @GabrieleGiuseppini 。 . . logparser 支持case 和having,所以不支持这很奇怪。我添加了另一种可能的方法。
  • 是的,Logparser 确实支持“有”和“案例”,但我也有其他情况,其中“案例”的支持非常有限。即使使用“-q:OFF”参数,我也只得到 Error: Syntax Error: : not a valid Uhm 在第二个示例中,我是否必须替换“t”在第二个选择语句中? select distinct hostname from '[LOGFILEPATH]' where not exists (select 1 from t t2 where t2.hostname = t.hostname and t2.RegKey like 'PromptOnSecureDesktop') 错误:语法错误::NOT 运算符后不跟
  • t 是您的表的名称。
猜你喜欢
  • 2021-02-09
  • 2022-01-23
  • 2014-10-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
  • 1970-01-01
相关资源
最近更新 更多