162. Number of orders per brand

easy walmart

  • ************************************************************************.
  • ********************************************

Table 1: walmart_brand

  col_name    | col_type
--------------+-------------------
brand_id      | bigint
brand_name    | text
product_id    | bigint

Table 2: walmart_order

  col_name    | col_type
--------------+-------------------
order_id      | bigint
product_id    | bigint
order_dt      | date
qty           | integer

Sample results

 brand_id | count
----------+-------
     1001 |    10
     1002 |     5
     1003 |     3

Solution postgres

SELECT B.brand_id, COUNT(order_id) AS cnt
FROM walmart_order O
INNER JOIN walmart_brand B
ON B.product_id = O.product_id
WHERE order_dt >= '2021-08-01'
AND   order_dt <= '2021-08-31'
GROUP BY B.brand_id;
    

Explanation

This query retrieves the number of orders made for each brand of product sold on Walmart's online store during August 2021. It does so by joining the walmart_order and walmart_brand tables on the product_id column, and filtering the results to include only orders made between August 1st and August 31st. The result set is grouped by brand_id, and the count of orders for each brand is returned as cnt.

Expected results


More Walmart questions

ID Title Level FTPR
163 Average number of orders per brand walmart easy
32%
164 Orders distribution by brand walmart easy
28%
165 Session stitching walmart hard
17%
166 Top 10 customers based on spend growth walmart medium
11%