Skip to content
Advertisement

Find entity with the biggest difference in a given column

I hava table profiles and I want to get the account with the most gained followers. I am using Postgresql. Note current record and previous record are all on the same table but with different timestamps.

I have the logic in my mind but honestly I don’t know how to express/think of it in terms of a sql query. This is my expected output.

The gain is will be the difference.

Any assistance is highly appreciated.Thank you.

Advertisement

Answer

The below answer worked for me.

For more details and explanations check out this answer

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement