6 kyu
Analyzing the sales by product and date
2,142 of 2,141FArekkusu
Description:
Task
Given the information about sales in a store, calculate the total revenue for each day, month, year, and product.
Notes
- The
sales
table stores only the dates for which any data has been recorded - the information about individual sales (what was sold, and when) is stored in thesales_details
table instead - The
sales_details
table stores totals per product per date - Order the result by the
product_name
,year
,month
,day
columns - We're interested only in the product-specific data, so you shouldn't return the total revenue from all sales
Input tables
----------------------------------------
| Table | Column | Type |
|---------------+------------+---------|
| products | id | int |
| | name | text |
| | price | numeric |
|---------------+------------+---------|
| sales | id | int |
| | date | date |
|---------------+------------+---------|
| sales_details | id | int |
| | sale_id | int |
| | product_id | int |
| | count | int |
-----------------------------------------
Output table
--------------------------
| Column | Type |
|--------------+---------|
| product_name | text |
| year | int |
| month | int |
| day | int |
| total | numeric |
--------------------------
Example output
product_name | year | month | day | total
-------------+------+-------+-----+------
milk | 2019 | 01 | 01 | 200
milk | 2019 | 01 | 02 | 190
milk | 2019 | 01 | | 390
milk | 2019 | 02 | 01 | 240
milk | 2019 | 02 | | 240
milk | 2019 | | | 630
milk | | | | 630
Algorithms
Similar Kata:
Stats:
Created | Oct 20, 2019 |
Published | Oct 20, 2019 |
Warriors Trained | 5992 |
Total Skips | 618 |
Total Code Submissions | 20397 |
Total Times Completed | 2141 |
SQL Completions | 2142 |
Total Stars | 147 |
% of votes with a positive feedback rating | 85% of 251 |
Total "Very Satisfied" Votes | 195 |
Total "Somewhat Satisfied" Votes | 39 |
Total "Not Satisfied" Votes | 17 |
Total Rank Assessments | 8 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 8 kyu |