Another SQL question. I have the following query:
SELECT EXTRACT(epoch from dt) as diff
from (
     SELECT time_col - lag(time_col) OVER dt
     FROM myTable where elementID=1234
 ) as dt 
This calculates the time difference and I get e.g. the following result table for ElementID 1234:
34
345
6
2
...
However I want to do this for every element ID that is stored in the table elementTable. Here is my approach:
SELECT EXTRACT(epoch from dt) as diff
from (
     SELECT time_col - lag(time_col) OVER dt
     FROM myTable where elementID=any(select elementID from elementTable) 
 ) as dt 
This is very close to the wanted result, however I get everything in a single column. E.g.
34  <- For element id = 1234
345 <- For element id = 1234
6   <- For element id = 1234
2   <- For element id = 1234
83  <- For element id = x
4   <- For element id = x
6   <- For element id = x
...
What I want to have is this (ordered in columns by element id):
 1234 | x | ...
 ------------------
 34     83  ...
 345    4   ...
 6      6   ...
 2      
Sorry for bothering you with my SQL questions, I'm trying to learn...
 
     
     
    