Sobes.tech

Data Engineer

Anzeigen der Anzahl der Bestellungen und "Produkte der benötigten Kategorie in der Bestellung" für das Jahr 2021 in den Kategorien "Kleidung" und für 2022 in der Kategorie "Schuhe" (Endansicht: 2 Zeilen. Felder: Jahr, Anzahl der Produkte, Anzahl der Bestellungen) 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 = 'Kleidung' and Year(o.order_date) = 2021) or (g.cat_1 = 'Schuhe' and Year(o.order_date) = 2022) group by year_orders, g.cat_1 ) select year_orders, count_quan, count_orders from cte für 2025, Top-3 in jeder Kategorie nach Verkaufsmenge model with cte as( select cat_1, price, quantity, model, rank() over(partition by cat_1) as rk from Orders o join Goods g on o.order_id = g.order_id where Year(o.order_date) = 2025 ) für 2025, Top-3 in jeder Kategorie nach Verkaufssumme model with cte as( select g.cat_1, g.model, (price * quantity), rank() over(partition by g.cat_1) as rk from Orders o join Goods g on o.order_id = g.order_id where Year(o.order_date) = 2025 ) with cte as( select g.cat_1, g.model, sum(price * quantity) as sum_, rank() over(partition by g.cat_1 order by sum() desc) as rk from Orders o join Goods g on o.order_id = g.order_id where Year(o.order_date) = 2025 ) with cte1 as( select g.cat_1, g.model, sum(price * quantity) as sum_total, from Orders o join Goods g on o.order_id = g.order_id where Year(o.order_date) = 2025 ), cte2 as(select g.cat_1, g.model, sum_total, rank() over(partition by g.cat_1 order sum_total desc) as rk from cte1 ) select g.cat_1, g.model, sum_total from cte2 where rk <=3 with cte1 as( select g.cat_1 as cat_name, g.model as model, sum(price * quantity) as sum_total, from Orders o join Goods g on o.order_id = g.order_id where Year(o.order_date) = 2025 group by Year(o.order_date), g.model ), cte2 as(select cat_name, model, sum_total, rank() over(partition by cat_name order sum_total desc) as rk from cte1 ) select cat_name, model, sum_total from cte2 where rk <=3

169

1. Bestellungen: - order_date datetime NICHT NULL - user_id int NICHT NULL - order_id int NICHT NULL 2. Waren: - order_id int NICHT NULL - model int NICHT NULL - cat_1 varchar(50) NICHT NULL - price int NICHT NULL - quantity int NICHT NULL Werte in cat_1: - Kleidung - Schuhe - Kosmetik - Haushaltswaren - Spielzeug Zeigen Sie die Anzahl der Bestellungen und "Anzahl der benötigten Kategorieprodukte in der Bestellung" für das Jahr 2021 in den Kategorien "Kleidung" und für 2022 in der Kategorie "Schuhe" (Endform: 2 Zeilen. Felder: Jahr, Anzahl der Produkte, Anzahl der Bestellungen) 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 = 'Kleidung' and Year(o.order_date) = 2021 or g.cat_1 = 'Schuhe' and Year(o.order_date) = 2022 group by year_orders, g.cat_1 ) select year_orders, count_quan, count_orders from cte

160