У меня есть данные в двух таблицах, используя union, как мне получать самые высокие продажи каждый год?
with table1 as(
select "ProductA" as Product, 80000 as units_sold,"2016" as year union all
select "ProductB" as Product, 75000 as units_sold,"2016" as year union all
select "ProductC" as Product, 15000 as units_sold,"2016" as year
),
table2 as(
select "ProductA" as Product, 60000 as units_sold,"2017" as year union all
select "ProductB" as Product, 120000 as units_sold,"2017" as year union all
select "ProductC" as Product, 70000 as units_sold,"2017" as year
)
select * from table1 union all select * from table2
Как получить ответ, как показано ниже, используя union?
Product units_sold year
ProductA 80000 2016
ProductB 120000 2017