Update total-sales-amount-by-year.sql #120
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
this is a hard coded solution for the problem 1384. Total Sales Amount by Year (hard)
Write an SQL query to report the Total sales amount of each item for each year, with corresponding product name, product_id, product_name and report_year.
Dates of the sales years are between 2018 to 2020. Return the result table ordered by product_id and report_year.
drop table if exists #Product;
Create table #Product
(
product_id int not null,
product_name varchar(50) not null,
Constraint PK_Product_product_id Primary Key (product_id)
);
Truncate table #Product;
insert into #Product (product_id, product_name)
values
( 1 , 'LC Phone' ),
( 2 , 'LC T-Shirt' ),
( 3 , 'LC Keychain' );
select * from #Product;
drop table if exists #Sales;
Create table #Sales
(
product_id int not null,
period_start varchar(50) not null,
period_end date not null,
average_daily_sales int not null,
Constraint PK_Sales_product_id Primary Key (product_id)
);
Truncate table #Sales;
insert into #Sales (product_id , period_start , period_end , average_daily_sales)
values
( 1 , '2019-01-25' , '2019-02-28' , 100 ),
( 2 , '2018-12-01' , '2020-01-01' , 10 ),
( 3 , '2019-12-01' , '2020-01-31' , 1 );
select * from #Sales;