Skip to content

Tag: sql

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…

Query not returning expected data

I’m looking for an explanation for why 1 of the following 3 queries aren’t returning what I am expecting. Assume the following: Anmodning with ANNo=1, ANCpr=1111112222 And the Person table doesn’t have a row with PSCpr=111111-2222 Queries are executed in Management Studio against a SQL Serve…

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

How to add a ranking to a pyspark dataframe

I have a pyspark dataframe with 2 columns – id and count. I want to add a ranking to this by reverse count. So the highest count has rank 1, second highest rank 2, etc. testDF = spark.createDataFrame([(DJS232,437232)], [“id”, “count”]) I first tried using and this worked, ish. It…

Sum up all values from a list PLSQL

I want to sum up all values from a INDEX BY TABLE list. In the list there are values like this: 24000, 4500, 7890 and so on. This is the code: Answer Lets assume that you have an associated array and you want to sum up the values within it. And, lets also assume that the associative array’s index is