Skip to content
Advertisement

Coalesce of multiple values group by date in postgres

I have a table as shown below:

[actual]: https://i.stack.imgur.com/267Ew.png

I need to select columns based on identity_no and also, need to select non zero/non null column values grouped by src_date. so when I query on the identity_no, I want something like: result

I need a postgresql statement or even a function is ok. I tried with coalesce. but i can’t do group by on src_date. Here src_date is a string and not a date

Advertisement

Answer

Use group by and max()

select scr_date,max(upload) as upload, max(download) as download, identity_no, max(email) as email,
max(phone) as phone, min(id) as id
from tablename
group by scr_date,identity_no
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement