'Listing products sold within a date range and order them by quantity sold

The task is: List the products according to the quantity they were sold in winter from less to many.

I have data like below.

Products

product_code product_name
3334 AAA
8388 BBB

Sales

sales_code product_code sales_date
5577 3334 25-12-2019 12:29
5578 8388 14-03-2020 13:30

Desired Result

produ_code product_name Quantity
3334 AAA 55
8388 BBB 97

We know that the winter months are December, January, and February. According to the dates I have to find quantity.

I don't know how to start but

(WHERE sales.sales_date
   AND sales.sales_date BETWEEN '01-12- 00:00:00' AND '28-02- 00:00:00'
 GROUP 
    BY sales_products.products_id) 

Can you help?

sql


Solution 1:[1]

Try this query:

 SELECT a.product_code,
       a.product_name,
       count(*) as Quantity
  FROM Products a, 
       Sales b
 WHERE a.product_code = b.product_code
   AND sales.sales_date 
       BETWEEN '01-12- 00:00:00' AND '28-02- 00:00:00' 
GROUP BY a.product_code,
         a.product_name; 

Thank you.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Massi FD