$query = ' SELECT span, MAX(ts) AS ts FROM my_table GROUP BY span';