【问题标题】:How to use a WHERE clause for a query in an influx database?如何在流入数据库中使用 WHERE 子句进行查询?
【发布时间】:2021-02-05 15:23:12
【问题描述】:

我想在 influx 数据库中进行查询以选择状态不等于 200 的条目。

我尝试了以下方法:

select * from http_reqs where status!=200 limit 30;
select * from http_reqs where "status"!=200 limit 30;

在这里我没有得到任何结果。

select * from http_reqs where status!="200" limit 30;
select * from http_reqs where "status"!="200" limit 30;

在这里我得到所有结果(即使是状态=200 的条目)

我做错了什么?

此外,以下查询不会返回任何内容:

select status from http_reqs limit 300;

我很困惑。

但是,以下查询会返回一些内容

select * from http_reqs limit 300;

它返回 300 个带有以下标头的条目:

time error error_code method name proto scenario status tls_version type url value

【问题讨论】:

  • status的数据类型是什么?如果是字符串,则可能有隐藏字符,例如空格。如果没有where 的查询没有返回任何内容,那么您的表是空的。
  • 没关系,我确实查询了所有数据,将其放入文件中,然后使用 python 脚本进行实际查询。这个废话容易得多
  • @GordonLinoff status 似乎是一个没有隐藏字符的字符串,因为用于从该 SQL 查询中选择条目的 python 脚本工作正常。

标签: sql influxdb


【解决方案1】:

InfluxDB 不是废话。您只需要学习它 - 它不是 SQL 数据库!我敢打赌你的status 是标签,所以在 SELECT 部分只使用标签真的没有意义。我猜它也是一个字符串类型,所以正确的查询语法应该是:

SELECT * 
FROM http_reqs 
WHERE "status"!='200'
LIMIT 30

如果它不起作用,请不要怪我,因为这几乎是盲目的猜测。您没有提供您的测量结构(字段/标签及其类型)。

【讨论】:

  • 感谢您的回答,它似乎工作!那么这里的引用类型很重要(单引号与双引号)?另外,measurement structure 是什么意思?
  • @Alex 从 SQL 思维到 InfluxDB 思维的快速过渡指南(但它不是 1:1 映射,请始终阅读 InfluxDB 文档):table -> measurement, column which can be aggregated with aggregation function -> fieldcolumn which can be used for filtering, grouping -> tag,where 部分中的列定义应在 "" 中,文本值应在 '' 中。
【解决方案2】:

我认为“状态”功能不完全是 int,它似乎混合了 int 和 chars。尝试将特征类型转换为 int,然后在查询中使用它。

【讨论】:

  • 我什至无法执行以下查询:select status from http_reqs limit 3; 我得到零结果!
  • 或者这个查询:select "method" from http_reqs limit 3;
  • 这里我得到一个错误:select 'method' from http_reqs limit 3;
猜你喜欢
  • 1970-01-01
  • 2018-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-18
  • 2017-02-25
  • 2014-01-01
相关资源
最近更新 更多