0% found this document useful (0 votes)
8 views5 pages

Rupesh Task-03 (Veracitiz)

The document provides SQL code to create a table and insert financial data for the years 2022 and 2023. It includes a view that calculates the year-wise, subcategory and category-wise amounts, along with the net difference and percentage increase between the two years. The final query retrieves this data and includes a total income summary.

Uploaded by

riokumar3757
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views5 pages

Rupesh Task-03 (Veracitiz)

The document provides SQL code to create a table and insert financial data for the years 2022 and 2023. It includes a view that calculates the year-wise, subcategory and category-wise amounts, along with the net difference and percentage increase between the two years. The final query retrieves this data and includes a total income summary.

Uploaded by

riokumar3757
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Tak-03

Q.1)
Based on below mentioned data create a sql query that will generate the Year
Wise, Subcategory and Category wise Amount and generate Net_difference
between mentioned year and % increase in this year.
Net_difference = yr_2023- yr_2022
% increased = yr_203-yr_202 * 100 / yr_2023
CREATE TABLE FinancialData (
RowId int,
Year INT,
Category VARCHAR(50),
SubCategory VARCHAR(50),
Amount DECIMAL(18, 2)
);

INSERT INTO FinancialData (RowId, Year, Category, SubCategory, Amount)


VALUES
(1, 2022, 'Revenue', 'Interest Income', 150000),
(2, 2022, 'Revenue', 'Remittance Income', 80000),
(3, 2022, 'Revenue', 'Fees and Commission', 60000),
(4, 2022, 'Revenue', 'Other Charges', 40000),
(5, 2022, 'COGS', 'Interest Charges', 50000),
(6, 2022, 'COGS', 'Commission for Sale', 30000),
(7, 2022, 'COGS', 'Other Expenses', 20000),
(8, 2023, 'Revenue', 'Interest Income', 157500),
(9, 2023, 'Revenue', 'Remittance Income', 84000),
(10, 2023, 'Revenue', 'Fees and Commission', 63000),
(11, 2023, 'Revenue', 'Other Charges', 42000),
(12, 2023, 'COGS', 'Interest Charges', 52500),
(13, 2023, 'COGS', 'Commission for Sale', 31500),
(14, 2023, 'COGS', 'Other Expenses', 21000),
(15, 2024, 'Revenue', 'Interest Income', 165000),
(16, 2024, 'Revenue', 'Remittance Income', 88000);
create view receipt as
(
select Category, source, Year_2022, Year_2023, (Year_2023 - Year_2022) AS
Net_Difference ,
round(((Year_2023-Year_2022)*100)/Year_2023, 10) As Percentage_increased
from
(
select Category, SubCategory As source,
SUM(CASE WHEN YEAR=2022 THEN (CASE WHEN Category='COGS' THEN -
Amount ELSE Amount END) END) AS Year_2022 ,
SUM(CASE WHEN YEAR=2023 THEN (CASE WHEN Category='COGS' THEN -
Amount ELSE Amount END) END) AS Year_2023
from FinancialData
group by Category, SubCategory
) as c
);
select Category, source, Year_2022, Year_2023,
Net_Difference,Percentage_increased from receipt
UNION
Select 'Total Income','', Sum(Year_2022), SUM(Year_2023),
SUM(Net_Difference), null from receipt;

You might also like