SELECT datetime(Table1.stamp), Table1.value, count(Table2.value), avg(Table2.value) FROM Table1 LEFT JOIN Table2 ON Table2.stamp BETWEEN Table1.stamp - 0.005 AND Table1.stamp + 0.005 GROUP BY Table1.stamp;