I have two table bellow:
Table tb_lose
enter image description here
And table tb_profit
enter image description here
Output, i need join two table and result will bellow:
enter image description here
All table, code, i use ms sql server for exam.
I want implement on oracle DB.
Thank!
I try join code bellow:
with lose_tmp as(
select * from TB_Lose
),
profit_tmp as(
select * from TB_Profit
),
tmp_5 as (select a.Level, a.Lose, a.Name, b.Profit
from lose_tmp a
join (select Level, Profit, Name from profit_tmp) b
on a.Name = b.Name and a.Level = b.Level
Where a.Level = 5
),
tmp_10 as (select a.Level, a.Lose, a.Name, b.Profit
from lose_tmp a
join (select Level, Profit, Name from profit_tmp) b
on a.Name = b.Name and a.Level = b.Level
Where a.Level = 10
)
select a.Name,
v5.Lose Lose_5,
v5.Profit Profit_5,
v10.Lose Lose_10,
v10.Profit Profit_10
from lose_tmp a
left join tmp_5 v5
on a.Name = v5.Name and a.Level = v5.Level
left join tmp_10 v10
on a.Name = v10.Name and a.Level = v10.Level
And result:
enter image description here
New contributor
mrTom Tom is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.