Expand|Select|Wrap|Line Numbers
- part price_list price
- 401 WSPL 1.6
- 401 LEVEL-70 1.3
- 404 WSPL 3.0
- 404 LEVEL-70 3.3
- 502 WSPL 2.0
- 600 LEVEL-70 4.0
which is a combination of the two price-lists as a new price_list WSPL70.
The criteria being
1. If a price for WSPL and LEVEL-70 exists, use the WSPL price
2. If only one price exists use that
I can JOIN to another table called products with the same parts.
The WSPL70 prices must be updated weekly from the same table
with any new products inserted
So I thought along the lines of
Expand|Select|Wrap|Line Numbers
- DELETE FROM price_breaks WHERE price_list = 'WSPL70';
- INSERT INTO price_breaks
- (part,price_list,price)
- VALUES
- (SELECT COALESCE (pl.part,alt.part) part
- 'WSPL70' price_list,
- COALESCE (pl.price,alt.price) price,
- FROM products
- JOIN price_breaks AS pl
- ON (part.part = pl.part
- AND pl.price_list = 'WSPL')
- LEFT JOIN price_breaks AS alt
- ON (part.part = alt.part
- AND alt.price_list = 'LEVEL-70'
- AND pl.price_list IS NULL))
because the first JOIN filters them out.
If I change this to a LEFT JOIN
every part in products is returned with NULL values
whereas a RIGHT JOIN returns all the other price_lists (not shown in eg)
Can anybody help with this
Also, can I INSERT INTO a table with data from a sub-query from the same table as shown