skip to Main Content

How to use first_value window function to get last non null value in Postgresql

I want to perform a fill-down activity in PgSQL DDL: create table brands ( id int, category varchar(20), brand_name varchar(20) ); insert into brands values (1,'chocolates','5-star') ,(2,null,'dairy milk') ,(3,null,'perk') ,(4,null,'eclair') ,(5,'Biscuits','britannia') ,(6,null,'good day') ,(7,null,'boost') ,(8,'shampoo','h&s') ,(9,null,'dove'); Expected output is: category…

VIEW QUESTION

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