1. Pasūtījumi:
- order_date datetime NE NULL
- user_id int NE NULL
- order_id int NE NULL
2. Preces:
- order_id int NE NULL
- model int NE NULL
- cat_1 varchar(50) NE NULL
- price int NE NULL
- quantity int NE NULL
Vērtības cat_1:
- Apģērbi
- Apavi
- Kosmētika
- Mājsaimniecības preces
- Rotaļlietas
Parādīt pasūtījumu skaitu un "nepieciešamo produktu skaitu kategorijā pasūtījumā" par 2021 gadu kategorijā "Apģērbi" un par 2022 gadu kategorijā "Apavi"
(galīgais skats: 2 rindas. Lauki: gads, produktu skaits, pasūtījumu skaits)
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 = 'Apģērbi' and Year(o.order_date) = 2021 or
g.cat_1 = 'Apavi' and Year(o.order_date) = 2022
group by year_orders, g.cat_1
)
select year_orders, count_quan, count_orders
from cte