Skip to content

Tag: postgresql

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 q…

Why SUM values are wrong in postgresql query?

I use postgresql and I have trouble in forming the correct query to get the desired result. I have a query And it gives me result as below. I wish to get the result like So I tried to SUM the third column and so changed the query a bit like this, But the result is like below, Fist this

SQL – Postgres string agg is giving duplicates

Im trying to collect the foreign key mapping from system tables. And I used this below query. query 1: But this won’t provide the Primary tables columns that are pointing as Fk. So I found this query on Stackoverflow. query 2 Now this query gives individual columns. Lets say there is a FK like (logid, i…

Postgres how to return values in between Min column and Max column

totally new in learning postgres/SQL I have a table called error_table that looks like this: but I am having a hard time generating a query on how to do this dynamically when my input number is 160, I would like to return the error_percent value 4.6 because 160 sits between the min column 100 and max column 2…