• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: SQL: Learning About Gap-And-Island Problems

Resolved: SQL: Learning About Gap-And-Island Problems

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve SQL: Learning About Gap-And-Island Problems

Question:

I am working with Netezza SQL.
In a previous question (Replacing CTE’s with Individual Queries) I learned about the basics of “Gap and Island Problems” in which the goal is to “fill” missing records for each name.
Suppose there is a table with the names of different people over different years (some of the years are missing). Lets assume that each person has favorite color, favorite food and favorite sport – and this information DOES NOT change over the years. However, the age of each person DOES change each year.
In this problem, I am interested in filling missing information (e.g. age, sport, food, color) only between the min and the max year for each person. Specifically, I would like to learn how to do this problem without CTEs and through a “standard query”.
Here is what I have attempted so far:
But I am not sure how to adapt this SQL code to make the “age” information for each person change over the years.
Can someone please show me how to do this? Preferably, I would like to learn how to do this without Recursive CTE’s as they are not supported in Netezza.
Thanks!
Note: The final result should look something like this:

Best Answer:

I do not know about Netezza so much but if it supports window functions, you can use a LEAD to get the year of the next record in your table.
Personally, I would stop the work here and let whatever application is in charge of generating the final table take over from there with a nested loop. In pseudo-code:
That limits the query complexity and the amount of redundant data to be sent over a network.
If you still wish to get the expected table you mention right out of the database, simply join with years_table , although it needs to start on year 2000.
Better yet, replace your years_table with something in the line of what is presented here (I must admit it is slightly above what I know of that DBMS and I have no access to one to test):
I expect this to work but then again, have no access to a DB to test it.

If you have better answer, please add a comment about this, thank you!

Source: Stackoverflow.com

netezza sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Using AWK to count multiple patterns in a file

01/04/2023

Resolved: significance letter above bar graphic in wrong order

01/04/2023

Resolved: VBA – Applying border around the areas with value/text

01/04/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.