【问题标题】:InfluxDB how to get the last recorded valuesInfluxDB如何获取最后记录的值
【发布时间】:2018-07-23 12:50:10
【问题描述】:

有一个 Inflix DB 数据库,其中写入了值。如何获取名为“test”的设备的最后记录数据(例如,协议编号和时间)?我试图通过query 得到它,但它只返回一个点,尽管数据库中大约有 40 个。

以下是示例代码。

public static long getTime( String devName ) {

        InfluxDB influxDB = InfluxDBFactory.connect("http://10.10.1.72:8086");
        String sql = "select time, protocol from device";
        Query query = new Query( sql, dbName );
        QueryResult result = influxDB.query(query);

        Series series = result.getResults().get(0).getSeries().get(0);

        //long time = (long)(double)series.getValues().get(0).get(0);
        System.out.println(series.getColumns().get(0) + "=" + series.getValues().get(0).get(0) + " " + series.getValues().get(0).get(0).getClass().getName());
        System.out.println(series.getColumns().get(1) + "=" + series.getValues().get(0).get(1) + " " + series.getValues().get(0).get(1).getClass().getName());
        return 0;
    }

【问题讨论】:

    标签: java database influxdb


    【解决方案1】:

    您可以使用last函数获取最后一项:

    SELECT last(protocol) FROM device [optional: WHERE <your condition>]
    

    或者你可以使用LIMIT关键字(注意,我们应该使用降序):

    SELECT * FROM device ORDER BY desc LIMIT 1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-09
      • 2023-01-28
      • 1970-01-01
      • 1970-01-01
      • 2012-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多