Leetcode Problem 1479. Sales by Day of the Week

1479. Sales by Day of the Week

Leetcode Solutions

Pivot Table with Conditional Aggregation

  1. Perform a RIGHT JOIN between the Orders and Items tables on the item_id column to include all categories, even those without orders.
  2. Use the WEEKDAY function to determine the day of the week for each order_date.
  3. Use the SUM function with a CASE statement inside to conditionally sum the quantity for each day of the week.
  4. Group the results by item_category.
  5. Order the final result by item_category.
  6. Select the item_category and the conditional sums for each day of the week as the final output.
erDiagram
    Orders {
        int order_id
        int customer_id
        date order_date
        varchar item_id
        int quantity
    }
    Items {
        varchar item_id
        varchar item_name
        varchar item_category
    }
    Orders }|--|| Items : ""

Pandas GroupBy and Unstack

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...