WQL 不支持 TOP - 需要解决方法
WQL(基本上是 WMI 的 SQL)不支持 TOP 或 LIMIT 关键字。 Sql Server 使用 TOP 和许多其他 RDBMS 支持 LIMIT 等。
是否有一种解决方法可以模拟 SELECT 查询,使其表现得好像它有一个 TOP/LIMIT 子句,将结果集限制为某个任意数字?
或者是否有其他一些特定于 WQL 的关键字,其作用类似于 TOP 或 LIMIT?
WQL (basically SQL for WMI) does not support a TOP or LIMIT keyword. Sql Server used TOP and many other RDBMSs supprt LIMIT etc.
Is there a workaround to emulating a SELECT query to behave as though it had a TOP/LIMIT clause that limits the result set to some arbitrary number?
Or is there some other WQL-specific keyword that works like TOP or LIMIT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,没有办法单独使用 WQL 来模拟 TOP。
例外:如果您足够幸运能够查询一个 WMI 类,该类使用无间隙的升序数字实例编号作为键,那么您可以使用大于和小于比较来限制和分页结果。
可能是 ManagementClass.GetInstances() 而不是使用 WQL 查询可能允许您在收集了足够的实例后中途取消枚举,从而避免支付一次枚举整个列表的 CPU 和 RAM 成本。
请注意,据我所知,CIMV2 WMI 提供程序本身并不处理 WQL,而是仅依赖 WMI 枚举所有实例、处理 WQL 并在将结果返回给调用者之前过滤结果。但昂贵的部分(实际上获取底层 WMI 数据)仍然完成。因此,我认为使用 WQL 与使用 GetInstances() 并自行过滤结果相比,不会提高效率(对于本地 WMI 查询而言)——如果 GetInstances() 允许您中途取消,则 GetInstances()对于长结果集可能要便宜得多。
Nope, there's no way to simulate TOP using WQL alone.
Exception: if you're lucky enough to be querying a WMI class which has ungapped, ascending numeric instance numbers used as keys, then you can use greater-than and less-then comparisons to limit and page through the results.
It's possible that ManagementClass.GetInstances() instead of using a WQL query might allow you to cancel the enumeration midway once you've collected enough instances, and hence avoid paying the CPU and RAM cost of enumerating the whole list at once.
Note that, AFAIK, the CIMV2 WMI provider doesn't natively handle WQL-- instead it simply relies on WMI to enumerate all instances, process the WQL, and filter the results before returning them to the caller. But the expensive part (actually fetching the underlying WMI data) is still done. So I believe there's no efficiency gain to be had (for local WMI queries, that is) by using WQL vs. using GetInstances() and filtering the results yourself-- and if GetInstances() allows you to cancel midway, then GetInstances() may be much cheaper for long result sets.
正如贾斯汀所说。但我不确定你的具体要求。我正在使用 Visual Basic 做一个简单的项目,其中一部分是获取事件日志,列表视图由于应用程序日志的巨大尺寸(> 20MB)而失败,并且控件进入某种无限循环。我想限制所以这是伪代码
Like Justin has said. I am not sure about your exact requirement though. I was doing a simple project with Visual Basic and part of it was to fetch event log, the listview fails due to the huge size of Application log(>20MB) and the control enters into some kind of infinite loop. I wanted to limit so here is the pseudocode
使用“select xyz -First 1”进行管道传输,
例如:Get-WmiObject win32_ologicaldisk |select -First 1
pipe it with "select xyz -First 1"
eg: Get-WmiObject win32_logicaldisk |select -First 1