0
votes

Can anyone help me to get the query. I have 2 table in first table customer and 2018, 2019 order and profit data. in second table customer and 2020 0rder and profit data.

I want to write a query that will return all customer an thier order and profit in a different format.

I have attached the screenshot of data and output. Please help me on this.

Thanks in advanceenter image description here

1
What's your best guess so far? As a tip, I would recommend left joining each table onto a list of distinct customers, generated by taking the union of the customer id in both tablesCaius Jard
not getting how to implement thisPeeyush Jain
What kind of SQL database are you using? Does it support full outer join?Kendle

1 Answers

1
votes

use full outer join

select
coalesce(t1.customer,t2.customer) as customer,
t1.0rder2018.t1.profit2018,t1.order2019,t1.profit2019,
t2.order2020,t2.profit2020
 from table1 as t1 full outer join table2 t2
on t1.cutomer=t2.customer