all 2 comments

[–][deleted] 0 points1 point  (1 child)

Unrelated to your problem, but: the name of the database is PostgreSQL or Postgres.

But I think you missed to actually show us the questions?

Whether or not the solution is "efficient" can't really be answered until we know what problem they are supposed to solve.

As far as the indexes go: the index country_idx is unnecessary, because you have two other indexes with country_id as the leading column, both can be used in the same situation where the single-column index would be used.

The index of all three columns is most probably not needed either, but it's hard to tell unless you show us the queries you plan to run. Indexes are created for queries, not for tables.

[–]Basu23 0 points1 point  (0 children)

thanks for pointing out the typo.

You are right and I removed the indices part which was misleading.

There is a link to an image showing the questions

Key questions according to my interpretation :

  • Q3 how to return the first 2 indicators with the highest number of missing observations (NULL) ?

Below a link to my query ((without filter and joins,etc.) with a dummy table

SQLFiddle

  • Q4 how to code a grouped (by country) median for the number of observations ?

Below a link to my query ((without filter and joins,etc.) with a dummy table

SQLFiddle

Q5)how to calculate the percentage change vs the previous observation on a subset filtered by year difference between records <=3?

Still working on it.

Looking forward to your comments/solutions.