93. number of sales for each product this month

easy amazon

***********

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

Table: orders

An eCommerce company's online order table.

  col_name    | col_type
--------------+-------------------
order_id      | bigint
product_id    | bigint
customer_id   | bigint
order_dt      | date
qty           | integer
unit_price_usd| float
channel       | varchar(20) -- mobile, desktop

Sample results

 product_id | sum
------------+-----
   10000023 |  92
   10000093 | 114
   10000077 |  92
   10000095 |  77
   10000045 | 136
   10000036 |  75
   10000019 |  88
   10000096 | 113
   10000039 |  96
   10000010 | 113
   10000038 | 105
   10000084 |  97

Solution postgres

SELECT product_id, SUM(qty)
FROM orders
WHERE order_dt >= '2021-08-01'
AND order_dt < '2021-09-01'
GROUP BY product_id;
    

Explanation

This query is selecting the product_id and the sum of quantities ordered for each product within a specific time period. The time period is defined by the WHERE clause, which specifies that only orders placed between August 1, 2021 and September 1, 2021 should be included in the results.

The results are grouped by product_id using the GROUP BY clause. This means that the sum of quantities ordered will be calculated for each unique product_id in the orders table.

Overall, this query is useful for analyzing sales data for specific products during a particular time frame.

Expected results


More Amazon questions

ID Title Level FTPR
94 Top 3 products vs. bottom 3 products amazon medium
7%
95 Candidate products for subscription amazon hard
13%
108 Free premium membership amazon hard
16%
109 Top 3 most popular product categories amazon easy
11%
110 Most popular product by category amazon medium
12%
111 Second most popular product amazon medium
16%
112 Top 3 customers amazon easy
30%
113 Daily cumulative spend amazon easy
11%
114 Dod revenue change rate amazon easy
15%
115 Rolling average revenue amazon hard
28%
116 Top answers day by device amazon easy
14%
117 Rolling 7 days total answers amazon easy
35%
175 Employees' email account amazon easy
14%
176 Employees' annual bonus amazon easy
12%
177 Purchases by platform report amazon medium
10%