I have a problem with a complex parent/child relationship. It is many-to-many, which is to say one parent can have many children and one child can have many parents. In addition, a child can be a parent.
I understand the need for an intermediate table to resolve the many-to-many and I am able to write SQL to query this side of the problem. The real issue is when a child becomes a parent.
To use a typical parts database. A sale is made of part A. Part A is comprised of Parts B & C. Part B is comprised of Parts D & E. I need to know the overall cost of Part A. By summing the cost of D & E (which is Part B), plus Part C. The problem is that there are changes made to the ratios of Parts D & E in order to produce Part B. Changes are also made to the ratios of Parts B & C to produce Part A. These changes are preserved in history with effective and expiration dates in the base table.
The question is: Since the cost can vary over time, how do I find the cost of Part A in time? I need to do this with SQL, please don't point me to programming.
I understand the need for an intermediate table to resolve the many-to-many and I am able to write SQL to query this side of the problem. The real issue is when a child becomes a parent.
To use a typical parts database. A sale is made of part A. Part A is comprised of Parts B & C. Part B is comprised of Parts D & E. I need to know the overall cost of Part A. By summing the cost of D & E (which is Part B), plus Part C. The problem is that there are changes made to the ratios of Parts D & E in order to produce Part B. Changes are also made to the ratios of Parts B & C to produce Part A. These changes are preserved in history with effective and expiration dates in the base table.
The question is: Since the cost can vary over time, how do I find the cost of Part A in time? I need to do this with SQL, please don't point me to programming.