tags:

views:

58

answers:

2

2 Tables with the below model: Id: long unique; timestamp:long; price:double

The data in both tables are identical except timestamp. Timestamp is given as unix_time in ms.

Quest: how many pairs have a bigger time difference than 1000ms ?

+1  A: 

Try this:

SELECT COUNT(*)
FROM Table1 t1 INNER JOIN Table2 t2 ON t1.id = t2.id
WHERE 
    (t1.timestamp - t2.timestamp > 1000) or 
    (t2.timestamp - t1.timestamp > 1000)
Roee Adler
@Rax, Tried your query. It showing desired result's. Thanks a ton !
Siv
A: 

assuming the IDs are same for both tables and timestamp is the only different field

assume these are your tables

ID | timestamp | price

we will call them table1 and table2

select count(*) from table1 t1
 inner join table2 t2 on t1.ID=t2.ID
 where (t1.timestamp-t2.timestamp) > 1000
 or (t2.timestamp-t1.timestamp)>1000
Saeros
@Saeros, I tried your query, But i dont require group by. I just need the count only and that too Id column is having unique right.. thank you for your answer!
Siv