DB2: Joining 2 tables with priority
I have 2 almost identical tables like this example:
item_list
store item price ------------------------- store1 SKU2388 200 store1 SKU2377 150
season_list
store item price season_start season_end ------------------------------------------------------- store1 SKU2377 100 12/10/10 31/12/10 store1 SKU2310 300 12/10/10 31/01/11
There will be multiple stores, and sometimes with multiple seasonal items specific to some stores that only available once in a time then disappears, and won't make it to normal items list. There will also be some normal items with promotional price on specific period.
Now, how can I make a compilation of these 2 tables, with all prices from normal items, combined with开发者_如何学Python all seasonal items, and if there are some conflicting items, the query will return the one on season_list and discard those on item_list?
Thank you for your help :)
select COALESCE(seasonal.price,normal.price)
from normal left outer join seasonal
on normal.id= seasonal.id
column and table name is not what you mentioned but hope to get the idea.
It joins two tables and when the seasonal price in not exists or is null it returns the normal price.
精彩评论