Skip to content
Advertisement

Compare values from one table with average calculation of value with same properties in other table

First post here… I’m trying to create select values from tableA in last 5 minutes and to compare those values each row by row with average(value) from another table.

For example:

tableA

tableB is basicaly the same, only values and time_stmp are different

tableB

Now, I want to create select statement where I’ll compare fields (values) from tableA in last 3 minutes with average value of tableB where name and location are same.

I tried something like:

but didn’t quite worked…

Output should be only values from tableA where value is less then average value of complete second table.

Any suggestion?

Advertisement

Answer

If I understand correctly:

For performance, you want indexes on tableB(name, location, value) and tableA(time_stamp).

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement