Skip to content
Advertisement

Tag: postgresql-14

Filtering in count function – Postgresql

I have the following query which gives me the amount of referrals users have. However, I would like to only count the referral if the referred user has activated the premium plan. How could this be achieved? Dbfiddle here. I am using PostgreSQL version 14. Answer You can try to use FILTER clause or condition aggregate function. Edit From you

Based on previous records, stop sum fields

I have a table like this: My goal is to obtain sum of points from date now to date that the point is greater than equal to 1 and stop sum of fields before that date. In the example above (order by date), the answer is sum of points date now(2022/01/06) to the date 2022/01/04 and equals 9 + 7

Advertisement