I have 2 tables
1-Table Price with 3 columns:
- part_id (there is repeat)
- effective_date (same part_id have different effective_date)
- part_price
2-Table Usage with 3 Columns:
- part_id (no repeat)
- usage_p1
- usage_p2
I want to get the newest price for parts on p1( p2 same logic);
I have tried to use SELECT to fill out the latest effective_date price and the usage_p1 by:
SELECT part_id, MAX(Effective_date) AS Latest_date
FROM Price
GROUP BY part_id
SELECT Usage_id FROM Usage WHERE Usage_p1>=1
but how can i proceed with these 2 selected result, or it is just impossible to proceed?
If I have to separate the Usage Table into 2 much simple tables P1 and P2. Table P1 only have 2 columns: part_id and usage_p1.
SELECT price.part_id, MAX(Effective_date) AS Latest_date, price.part_price,
P1.usage_pi, usage_P1*part_price AS value_p1
FROM Price
INNER JOIN P1 ON Price.part_id=P1.part_id
GROUP BY P1.part_id
Is this way optimal or kind of wast space? enter image description here