Hi Arimitra, I'm not sure I understood your question but I wrote the attached code that could be useful. In general, the code does this: Step 1: Create sample data. Step 2: Generate a table that shows the count of subcategories and the total sales amount per each subcategory, everything grouped by date. To achieve this result I did the following: 2.1. Extract a list of distinct subcategories values. 2.2. Extract a list of disctinct dates. 2.3. Perform a cross join in order to generate a list with all posible combinations of subcategories per date. 2.4. Calculate a table with the count of subcategories per date and their corresponding total sales amount. 2.5. Perform a left join in order to complement the table from step 2.3 with its matching subcategory count and total sales amount. As we don't have subcategories for all dates you'll get a missing value for those cases. You may find this process long, and your original question was related to having one single query to achive the result. In response to this question, you can take a look on the next step. Step 3: This piece of code is a way to have a single query to do the previous steps, it involves subqueries and Cartesian products, but it is NOT a viable solution and I wouldn't suggest by any means use of it, because of the mentioned Cartesian products and remerging (iterative) processes involved. It is not a good practice and you shouldn't consider it for a real implementation, in fact, step 2.3 will generate a Cartesian product so please keep in mind only steps 1 and 2, they can be considered as a possible solution for this example. Best Regards, Oscar
... View more