select distinct foo_id key, last_value(value) over ( partition by foo_id order by id ) value from foo_data where foo_id <> ? and aktivity is true and key = 'name';