0

I am using influxDB and I would like to extract some values which is greater than certain threshold in other table.

For example, I have two tables as shown in below.

Table A

Time     value
1         15
2         25
3         9
4         22

Table B

Time     threshold
1         16
2         12
3         13
4         15

Give above two tables, I would like to extract three values which is greater than first row in Table B. Therefore what I want to have is as below.

   Time     value
    2         25
    4         22

I tried it using below sql query, but it didn't give any correct result.

select * from data1 where value > (select spec from spec1 limit1);

Look forward to your feedback.

Thanks.

sclee1
  • 1,095
  • 1
  • 15
  • 36

1 Answers1

0

Integrate the condition in an inner join:

select * from tableA as a
inner join tableB as b on a.id=b.id and a.value > b.threshold

When your time column doesn't only include integer values, you have to format the time and join on a time range. Here is an example: SQL join on time range

Johann
  • 349
  • 2
  • 9