Sobes.tech
Middle

1. Objednávky: - order_date datetime NIE NULL - user_id int NIE NULL - order_id int NIE NULL 2. Tovar: - order_id int NIE NULL - model int NIE NULL - cat_1 varchar(50) NIE NULL - price int NIE NULL - quantity int NIE NULL Hodnoty v cat_1: - Oblečenie - Obuv - Kozmetika - Domáce potreby - Hračky Zobraziť počet objednávok a "počet potrebných produktov v kategórii v objednávke" za rok 2021 v kategóriách "Oblečenie" a za rok 2022 v kategóriách "Obuv" (finálny pohľad: 2 riadky. Polia: rok, počet produktov, počet objednávok) 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 = 'Oblečenie' and Year(o.order_date) = 2021 or g.cat_1 = 'Obuv' and Year(o.order_date) = 2022 group by year_orders, g.cat_1 ) select year_orders, count_quan, count_orders from cte