1. Užsakymai:
- order_date datetime NE NULL
- user_id int NE NULL
- order_id int NE NULL
2. Prekės:
- order_id int NE NULL
- model int NE NULL
- cat_1 varchar(50) NE NULL
- price int NE NULL
- quantity int NE NULL
Reikšmės cat_1:
- Drabužiai
- Batai
- Kosmetika
- Namų apyvokos daiktai
- Žaislai
Parodyti užsakymų skaičių ir "reikalingų produktų skaičių kategorijoje užsakymo metu" už 2021 metus kategorijoje "Drabužiai" ir už 2022 metus kategorijoje "Batai"
(galutinis vaizdas: 2 eilutės. Laukai: metai, produktų skaičius, užsakymų skaičius)
with cte as(
select
year(o.order_date) as year_orders,
g.cat_1,
count(distinct o.order_id) as count_orders,
sum(g.quantity) as count_quan
from Orders o
join Goods g on o.order_id = g.order_id
where g.cat_1 = 'Drabužiai' and Year(o.order_date) = 2021 or
g.cat_1 = 'Batai' and Year(o.order_date) = 2022
group by year_orders, g.cat_1
)
select year_orders, count_quan, count_orders
from cte