skip to Main Content

Postgresql – Aggregate functions are not allowed in FILTER

I have this SQL query: SELECT users.id, users.name, users.avatar, MAX(messages.created_at) max_created_at, MAX(messages.body) FILTER (WHERE messages.created_at = MAX(messages.created_at)) last_message, CASE WHEN(COUNT(messages.is_read) FILTER (WHERE is_read = false AND messages.from_id != 14) = 0) THEN true ELSE false END is_read, COUNT(messages.is_read) FILTER (WHERE…

VIEW QUESTION
Back To Top
Search