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 the sales_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

Stats:

CreatedOct 20, 2019
PublishedOct 20, 2019
Warriors Trained5992
Total Skips618
Total Code Submissions20397
Total Times Completed2141
SQL Completions2142
Total Stars147
% of votes with a positive feedback rating85% of 251
Total "Very Satisfied" Votes195
Total "Somewhat Satisfied" Votes39
Total "Not Satisfied" Votes17
Total Rank Assessments8
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • FArekkusu Avatar
  • Voile Avatar
Ad