SlideShare a Scribd company logo
1 of 30
SQL FINAL PROJECT
Data analyzed in this task are collected from Tokopedia (not the original data). The dataset is:
order_detail:
1. id → the unique number of order/id_order
2. customer_id → the unique number of customer
3. order_date → date when the transaction is carried out
4. sku_id → the unique number of a product (sku is stock
keeping unit)
5. price → the amount of money given in payment for
something
6. qty_ordered → the number of items purchased by customers
7. before_discount → the total price value of products
8. discount_amount → the discount value of the total product.
9. after_discount → the value of the total price after
aggregated by the discount
10. is_gross → shows that customers have not yet paid the
orders
11. is_valid → shows that customers have paid the orders
12. is_net → shows that the transaction is finished
13. payment_id → the unique number of payment method
sku_detail:
1. id → the unique number of a product (it can be used as a key for
joining)
2. sku_name → the name of the product
3. base_price → the price that is shown in the tagging
4. cogs → cost of selling one product
5. category → product category
customer_detail:
1. id → the unique number of a customer
2. registered_date → the date when a customer sign up as a member
Payment_detail:
1. id → the unique number of a payment
2. payment_method → the method of payment applied during
transaction
TABLE SCHEME
Business Questions
1. During the transactions that are carried out in 2021, in which month does the total transaction value
(after_discount) reach its peak? Use is_valid = 1 to filter the data. Source table: order_detail.
2. During the transactions that occurred in 2022, which category generated the largest transaction? Use
is_valid = 1 to filter the data. Source table: order_detail, sku_detail.
3. Compare the transaction value for each category in 2021 with those in 2022. Identify which category
that showed an increase, and which category experienced a decrease in the value of transaction. Use
is_valid = 1 to filter the data. Source table: order_detail, sku_detail.
4. Identify the top 5 most popular methods of payment used in 2022 (based on total unique order) Use
is_valid = 1 to filter the data. Source table: order_detail, payment_method.
5. Sort the 5 products based on their value of transactions: Samsung, Apple, Sony, Huawei, Lenovo. Use
is_valid = 1 to filter the data. Source table: order_detail, payment_method.
TOOL
Answers and Steps
1. Copy the syntax from the order_detail file. Then click Run
to implement the syntax.
2. To present the table, type SELECT * FROM order_detail. And then Run
Table of order_detail in PostgreSQL
3. Copy the syntax of sku_detail. Then click Run.
4. To present the table, type SELECT * FROM sku_detail. And then Run
Table of sku_detail in PostgreSQL
Apply the same steps to create the tables of payment_detail and
customer_detail.
Table of payment_detail in PostgreSQL
Table of customer_detail in PostgreSQL
1. During the transactions that are carried out in 2021, in which month does the total transaction value
(after_discount) reach its peak? Use is_valid = 1 to filter the data. Source table: order_detail.
SELECT
to_char (order_date,'Month') AS month_transaction,
-- to_char is used to format the year, month, and date. AS is used as an alias for
the data that is taken from the order_date.
SUM(after_discount) AS total_transaction
-- calculate the total sum from ‘after_discount’. AS is used as an alias for the
calculation result.
FROM
order_detail
WHERE
is_valid = 1
AND EXTRACT (year FROM order_date) = 2021
-- Extract the month from order_date in 2021
GROUP BY
1
-- Group the data based on the result. We choose the month that shows the
highest total transactions.
ORDER BY
2 DESC
-- orders the result in descending form or from highest to the lowest. 2 is the
sum after_discount
LIMIT 1
Query to take the data from the database and present the result
Function to specify the dataset from which the data is taken
Function to filter the data
Limit the output. 1 means it gives the highest transaction
value as it only presents the first row.
August is the month with the highest total transaction value in
2021. Its total transaction is 227,862,744.
Result
2. During the transactions that occurred in 2022, which category generated the largest transaction? Use
is_valid = 1 to filter the data. Source table: order_detail, sku_detail.
SELECT
category,
SUM (after_discount) AS total_transaction
-- calculate the total sum from ‘after_discount’. AS is used as an alias for the
calculation result.
FROM
sku_detail AS sd
LEFT JOIN order_detail AS od
ON sd.id = od.sku_id
-- Left join means returning all records from sku_detail and the matched
records from the order_detail.
WHERE
is_valid = 1
AND EXTRACT (YEAR FROM order_date) = 2022
-- Extract the month from order_date in 2022
GROUP BY
1
-- Group the data based on the result. We choose the category that generates
the highest total transactions.
ORDER BY
2 DESC
-- orders the result in descending form or from highest to the lowest. 2 is the
sum after_discount
LIMIT 1
Query to take the data from the database and present the result
Function to filter the data
The category of product in sku_detail
Function to specify the dataset from which the data is taken
AS is the alias of sku_detail
AS is the alias of order_detail
Limit the output. 1 means it gives the highest transaction
value as it only presents the first row.
Mobiles and tablets are categories with the highest total transaction value in
2022. Its total transaction is 918,451,576
Result
3. Compare the transaction value for each category in 2021 with those in 2022. Identify which category
that showed an increase, and which category experienced a decrease in the value of transaction. Use
is_valid = 1 to filter the data. Source table: order_detail, sku_detail.
-- The comparison of transactions from each category in 2021 and 2022
SELECT
category,
SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2021-01-01'
AND '2021-12-31' THEN od.after_discount END) total_sales_2021,
-- CASE WHEN is the alternative function of IF-ELSE. If the data falls within the
range of dates above, then there will be value after_discount. END function is
added because if the data falls outside the range of dates above, then there will
be no value after_discount.
SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01'
AND '2022-12-31' THEN od.after_discount END) total_sales_2022
FROM
order_detail AS od
LEFT JOIN
sku_detail AS sd
ON sd.id = od.sku_id
-- Left join means returning all records from order_detail and the matched
records from the sku_detail.
WHERE
is_valid = 1
GROUP BY 1
ORDER BY 2 DESC
Query to take the data from the database and present the result
The category of product in sku_detail
AS is the alias of order_detail
Function to filter the data
Group by category
Orders the result in descending form or from highest to the lowest. 2 is the
sum after_discount
Function to specify the dataset from which the data is taken
-- Categories that show growth and categories that show slump
WITH
full_transaction as (
-- In this part, the WITH function is added. It is because, in this part, there are
some conditional functions. WITH helps to define the first functions before
reading the main queries.
SELECT
category,
SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2021-01-01'
AND '2021-12-31' THEN od.after_discount END) total_sales_2021,
SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01'
AND '2022-12-31' THEN od.after_discount END) total_sales_2022
-- CASE WHEN is the alternative function of IF-ELSE. If the data falls within the
range of dates above, then there will be value after_discount. END function is
added because if the data falls outside the range of dates above, then there will
be no value after_discount.
FROM
order_detail AS od
LEFT JOIN
sku_detail AS sd
ON sd.id = od.sku_id
WHERE
is_valid = 1
GROUP BY 1
ORDER BY 2
DESC
)
AS is the alias of order_detail
Left join means returning all records from order_detail and the matched
records from the sku_detail.
Function to filter the data
Orders the result in descending form or from highest to the lowest. 2 is the
sum after_discount
Function to specify the dataset from which the data is taken
SELECT
full_transaction.*,
total_sales_2022 - total_sales_2021 AS growth_value
-- The star symbol means that all columns in full_transaction are retrieved. Then
create one column where total_sales_2022 is minus by total_sales_2021. The
result will be known as growth_value.
FROM
full_transaction
ORDER BY
4 DESC
Function to specify the dataset from which the data is taken
Result
The comparison of transactions from each category in 2021 and 2022
Result
Categories that show increase and categories that show decrease. Decrease is shown by
minus in the growth_value.
4. Identify the top 5 most popular methods of payment used in 2022 (based on total unique order) Use
is_valid = 1 to filter the data. Source table: order_detail, payment_method.
SELECT
payment_method,
COUNT (DISTINCT od.id) AS total_payment
--COUNT is used because we want to count the number of unique orders. As we
need to count total orders, we need to implement DISTINCT. When we use
DISTINCT, although there are 5 records, we can identify that it is actually one
transaction.
FROM
order_detail AS od
LEFT JOIN
payment_detail AS pd
ON pd.id = od.payment_id
-- Left join means returning all records from order_detail and the matched
records from the payment_detail.
WHERE
EXTRACT (Year FROM order_date) = 2022
AND
is_valid = 1
GROUP BY
1
ORDER BY
2 DESC
LIMIT 5
Function to specify the dataset from which the data is taken
Function to filter the data
Group by payment method
Limit the output. 5 means it gives 5 most used payment methods
which are located in the 5 first rows.
Result
5 most popular payment methods in 2022
5. Sort the 5 products based on their value of transactions: Samsung, Apple, Sony, Huawei, Lenovo. Use
is_valid = 1 to filter the data. Source table: order_detail, payment_method.
WITH full_transaction AS (
SELECT
CASE
WHEN (sku_name) like '%samsung%' THEN 'Samsung'
WHEN (sku_name) LIKE '%apple%' THEN 'Apple'
WHEN (sku_name) LIKE '%iphone%' THEN 'Apple'
WHEN (sku_name) LIKE '%imac%' THEN 'Apple'
WHEN (sku_name) LIKE '%macbook%' THEN 'Apple'
WHEN (sku_name) LIKE '%sony%' THEN 'Sonny'
WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei'
WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei'
WHEN (sku_name) LIKE '%lenovo%' THEN 'Lenovo'
END product_name,
SUM(after_discount) total_sales
FROM
order_detail AS od
LEFT JOIN sku_detail as sd ON sd.id = od.sku_id
WHERE
to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01' AND '2022-12-31'
AND is_valid = 1
GROUP BY 1
)
SELECT
full_transaction.*
FROM full_transaction
WHERE
product_name NOTNULL
ORDER BY
2 DESC
*Syntax explanation is on
the next page
Syntax Explanation
WITH full_transaction AS (
SELECT
CASE
WHEN (sku_name) LIKE '%samsung%' THEN 'Samsung'
WHEN (sku_name) LIKE '%apple%' THEN 'Apple'
WHEN (sku_name) LIKE '%iphone%' THEN 'Apple'
WHEN (sku_name) LIKE '%imac%' THEN 'Apple'
WHEN (sku_name) LIKE '%macbook%' THEN 'Apple'
WHEN (sku_name) LIKE '%sony%' THEN 'Sonny'
WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei'
WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei'
WHEN (sku_name) LIKE '%lenovo%' THEN 'Lenovo’
-- Regular expression function is used to identify the data text, for example, Samsung. The
LIKE function is also utilized as it has the meaning of “similar with”. There is a % symbol on
both sides of Samsung, which has a function to identify any string that contains “Samsung”
word.
END product_name,
SUM(after_discount) total_sales
FROM
order_detail AS od
LEFT JOIN sku_detail as sd ON sd.id = od.sku_id
WHERE
to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01' AND '2022-12-31'
AND is_valid = 1
GROUP BY 1
)
Function to specify the dataset from which the data is taken
Function to filter the data
SELECT
full_transaction.*
-- The star symbol means that all columns in full-transaction are
retrieved
FROM full_transaction
WHERE
product_name NOTNULL
-- The second temporary table aims to drop NOTNULL
ORDER BY
2 DESC 2 means product_name and total_sales. DESC
means sort from the highest to the lowest
Result
Samsung is the most popular product name as its total sales reach 97,552,288
Follow me!
Instagram : elyadawigatip
Twitter : @EliNoBishamon
LinkedIn : https://www.linkedin.com/in/elyada-
wigati-pramaresti-1a2387170/
Bootcamp Data Analysis
by @myskill.id

More Related Content

Similar to Final Project SQL - Elyada Wigati Pramaresti.pptx

Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with RCasper Crause
 
Cover PageComplete and copy the following to Word for your cover p.docx
Cover PageComplete and copy the following to Word for your cover p.docxCover PageComplete and copy the following to Word for your cover p.docx
Cover PageComplete and copy the following to Word for your cover p.docxfaithxdunce63732
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planMaria Colgan
 
Technical architecture for order management
Technical architecture for order managementTechnical architecture for order management
Technical architecture for order managementMohit kumar Gupta
 
Check printing in_r12
Check printing in_r12Check printing in_r12
Check printing in_r12Rajesh Khatri
 
DDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdfDDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdfEleonora Ciceri
 
Sqlserver interview questions
Sqlserver interview questionsSqlserver interview questions
Sqlserver interview questionsTaj Basha
 
Project report aditi paul1
Project report aditi paul1Project report aditi paul1
Project report aditi paul1guest9529cb
 
AIRBNB DATA WAREHOUSE & GRAPH DATABASE
AIRBNB DATA WAREHOUSE & GRAPH DATABASEAIRBNB DATA WAREHOUSE & GRAPH DATABASE
AIRBNB DATA WAREHOUSE & GRAPH DATABASESagar Deogirkar
 
SQL coding at Sydney Measure Camp 2018
SQL coding at Sydney Measure Camp 2018SQL coding at Sydney Measure Camp 2018
SQL coding at Sydney Measure Camp 2018Adilson Mendonca
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain PlanMaria Colgan
 
Experiments and Results on Click stream analysis using R
Experiments and Results on Click stream analysis using RExperiments and Results on Click stream analysis using R
Experiments and Results on Click stream analysis using RPridhvi Kodamasimham
 
1 – Implementing the Decorator Design Pattern (with St.docx
1  – Implementing the Decorator Design Pattern  (with St.docx1  – Implementing the Decorator Design Pattern  (with St.docx
1 – Implementing the Decorator Design Pattern (with St.docxhoney725342
 
Simple Spreadsheet Tips
Simple Spreadsheet TipsSimple Spreadsheet Tips
Simple Spreadsheet TipsInside Access
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionFranck Pachot
 

Similar to Final Project SQL - Elyada Wigati Pramaresti.pptx (20)

Company segmentation - an approach with R
Company segmentation - an approach with RCompany segmentation - an approach with R
Company segmentation - an approach with R
 
Data Warehousing
Data WarehousingData Warehousing
Data Warehousing
 
Set Analyse OK.pdf
Set Analyse OK.pdfSet Analyse OK.pdf
Set Analyse OK.pdf
 
Cover PageComplete and copy the following to Word for your cover p.docx
Cover PageComplete and copy the following to Word for your cover p.docxCover PageComplete and copy the following to Word for your cover p.docx
Cover PageComplete and copy the following to Word for your cover p.docx
 
Ground Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_planGround Breakers Romania: Explain the explain_plan
Ground Breakers Romania: Explain the explain_plan
 
MSA_8110_Final_Project
MSA_8110_Final_ProjectMSA_8110_Final_Project
MSA_8110_Final_Project
 
Technical architecture for order management
Technical architecture for order managementTechnical architecture for order management
Technical architecture for order management
 
Check printing in_r12
Check printing in_r12Check printing in_r12
Check printing in_r12
 
DDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdfDDD - 2 - Domain Driven Design: Tactical design.pdf
DDD - 2 - Domain Driven Design: Tactical design.pdf
 
Sqlserver interview questions
Sqlserver interview questionsSqlserver interview questions
Sqlserver interview questions
 
Project report aditi paul1
Project report aditi paul1Project report aditi paul1
Project report aditi paul1
 
AIRBNB DATA WAREHOUSE & GRAPH DATABASE
AIRBNB DATA WAREHOUSE & GRAPH DATABASEAIRBNB DATA WAREHOUSE & GRAPH DATABASE
AIRBNB DATA WAREHOUSE & GRAPH DATABASE
 
SQL coding at Sydney Measure Camp 2018
SQL coding at Sydney Measure Camp 2018SQL coding at Sydney Measure Camp 2018
SQL coding at Sydney Measure Camp 2018
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
 
Dfd2
Dfd2Dfd2
Dfd2
 
Experiments and Results on Click stream analysis using R
Experiments and Results on Click stream analysis using RExperiments and Results on Click stream analysis using R
Experiments and Results on Click stream analysis using R
 
Dwbi Project
Dwbi ProjectDwbi Project
Dwbi Project
 
1 – Implementing the Decorator Design Pattern (with St.docx
1  – Implementing the Decorator Design Pattern  (with St.docx1  – Implementing the Decorator Design Pattern  (with St.docx
1 – Implementing the Decorator Design Pattern (with St.docx
 
Simple Spreadsheet Tips
Simple Spreadsheet TipsSimple Spreadsheet Tips
Simple Spreadsheet Tips
 
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory optionStar Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
Star Transformation, 12c Adaptive Bitmap Pruning and In-Memory option
 

More from Elyada Wigati Pramaresti

More from Elyada Wigati Pramaresti (7)

Final Project Data Visualization - Elyada Wigati
Final Project Data Visualization - Elyada WigatiFinal Project Data Visualization - Elyada Wigati
Final Project Data Visualization - Elyada Wigati
 
SQL Basic Clause - Portfolio.pptx
SQL Basic Clause - Portfolio.pptxSQL Basic Clause - Portfolio.pptx
SQL Basic Clause - Portfolio.pptx
 
Working with Google Sheet - Portfolio.pptx
Working with Google Sheet - Portfolio.pptxWorking with Google Sheet - Portfolio.pptx
Working with Google Sheet - Portfolio.pptx
 
Intro to Statistics.pptx
Intro to Statistics.pptxIntro to Statistics.pptx
Intro to Statistics.pptx
 
Improvement as Data Analyst.pptx
Improvement as Data Analyst.pptxImprovement as Data Analyst.pptx
Improvement as Data Analyst.pptx
 
Kickstart Career as Data Analyst - Elyada Wigati Pramaresti.pptx
Kickstart Career as Data Analyst - Elyada Wigati Pramaresti.pptxKickstart Career as Data Analyst - Elyada Wigati Pramaresti.pptx
Kickstart Career as Data Analyst - Elyada Wigati Pramaresti.pptx
 
Microsoft Excel Basic to Advance - Sales Analysis
Microsoft Excel Basic to Advance - Sales AnalysisMicrosoft Excel Basic to Advance - Sales Analysis
Microsoft Excel Basic to Advance - Sales Analysis
 

Recently uploaded

Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionfulawalesam
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxolyaivanovalion
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxolyaivanovalion
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxolyaivanovalion
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Delhi Call girls
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023ymrp368
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxolyaivanovalion
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 

Recently uploaded (20)

Week-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interactionWeek-01-2.ppt BBB human Computer interaction
Week-01-2.ppt BBB human Computer interaction
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
꧁❤ Aerocity Call Girls Service Aerocity Delhi ❤꧂ 9999965857 ☎️ Hard And Sexy ...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
BigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptxBigBuy dropshipping via API with DroFx.pptx
BigBuy dropshipping via API with DroFx.pptx
 
Smarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptxSmarteg dropshipping via API with DroFx.pptx
Smarteg dropshipping via API with DroFx.pptx
 
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
Call Girls in Sarai Kale Khan Delhi 💯 Call Us 🔝9205541914 🔝( Delhi) Escorts S...
 
Data-Analysis for Chicago Crime Data 2023
Data-Analysis for Chicago Crime Data  2023Data-Analysis for Chicago Crime Data  2023
Data-Analysis for Chicago Crime Data 2023
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Mature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptxMature dropshipping via API with DroFx.pptx
Mature dropshipping via API with DroFx.pptx
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 

Final Project SQL - Elyada Wigati Pramaresti.pptx

  • 2. Data analyzed in this task are collected from Tokopedia (not the original data). The dataset is: order_detail: 1. id → the unique number of order/id_order 2. customer_id → the unique number of customer 3. order_date → date when the transaction is carried out 4. sku_id → the unique number of a product (sku is stock keeping unit) 5. price → the amount of money given in payment for something 6. qty_ordered → the number of items purchased by customers 7. before_discount → the total price value of products 8. discount_amount → the discount value of the total product. 9. after_discount → the value of the total price after aggregated by the discount 10. is_gross → shows that customers have not yet paid the orders 11. is_valid → shows that customers have paid the orders 12. is_net → shows that the transaction is finished 13. payment_id → the unique number of payment method
  • 3. sku_detail: 1. id → the unique number of a product (it can be used as a key for joining) 2. sku_name → the name of the product 3. base_price → the price that is shown in the tagging 4. cogs → cost of selling one product 5. category → product category customer_detail: 1. id → the unique number of a customer 2. registered_date → the date when a customer sign up as a member Payment_detail: 1. id → the unique number of a payment 2. payment_method → the method of payment applied during transaction
  • 5. Business Questions 1. During the transactions that are carried out in 2021, in which month does the total transaction value (after_discount) reach its peak? Use is_valid = 1 to filter the data. Source table: order_detail. 2. During the transactions that occurred in 2022, which category generated the largest transaction? Use is_valid = 1 to filter the data. Source table: order_detail, sku_detail. 3. Compare the transaction value for each category in 2021 with those in 2022. Identify which category that showed an increase, and which category experienced a decrease in the value of transaction. Use is_valid = 1 to filter the data. Source table: order_detail, sku_detail. 4. Identify the top 5 most popular methods of payment used in 2022 (based on total unique order) Use is_valid = 1 to filter the data. Source table: order_detail, payment_method. 5. Sort the 5 products based on their value of transactions: Samsung, Apple, Sony, Huawei, Lenovo. Use is_valid = 1 to filter the data. Source table: order_detail, payment_method.
  • 7. Answers and Steps 1. Copy the syntax from the order_detail file. Then click Run to implement the syntax.
  • 8. 2. To present the table, type SELECT * FROM order_detail. And then Run
  • 9. Table of order_detail in PostgreSQL
  • 10. 3. Copy the syntax of sku_detail. Then click Run.
  • 11. 4. To present the table, type SELECT * FROM sku_detail. And then Run
  • 12. Table of sku_detail in PostgreSQL Apply the same steps to create the tables of payment_detail and customer_detail.
  • 13. Table of payment_detail in PostgreSQL
  • 14. Table of customer_detail in PostgreSQL
  • 15. 1. During the transactions that are carried out in 2021, in which month does the total transaction value (after_discount) reach its peak? Use is_valid = 1 to filter the data. Source table: order_detail. SELECT to_char (order_date,'Month') AS month_transaction, -- to_char is used to format the year, month, and date. AS is used as an alias for the data that is taken from the order_date. SUM(after_discount) AS total_transaction -- calculate the total sum from ‘after_discount’. AS is used as an alias for the calculation result. FROM order_detail WHERE is_valid = 1 AND EXTRACT (year FROM order_date) = 2021 -- Extract the month from order_date in 2021 GROUP BY 1 -- Group the data based on the result. We choose the month that shows the highest total transactions. ORDER BY 2 DESC -- orders the result in descending form or from highest to the lowest. 2 is the sum after_discount LIMIT 1 Query to take the data from the database and present the result Function to specify the dataset from which the data is taken Function to filter the data Limit the output. 1 means it gives the highest transaction value as it only presents the first row.
  • 16. August is the month with the highest total transaction value in 2021. Its total transaction is 227,862,744. Result
  • 17. 2. During the transactions that occurred in 2022, which category generated the largest transaction? Use is_valid = 1 to filter the data. Source table: order_detail, sku_detail. SELECT category, SUM (after_discount) AS total_transaction -- calculate the total sum from ‘after_discount’. AS is used as an alias for the calculation result. FROM sku_detail AS sd LEFT JOIN order_detail AS od ON sd.id = od.sku_id -- Left join means returning all records from sku_detail and the matched records from the order_detail. WHERE is_valid = 1 AND EXTRACT (YEAR FROM order_date) = 2022 -- Extract the month from order_date in 2022 GROUP BY 1 -- Group the data based on the result. We choose the category that generates the highest total transactions. ORDER BY 2 DESC -- orders the result in descending form or from highest to the lowest. 2 is the sum after_discount LIMIT 1 Query to take the data from the database and present the result Function to filter the data The category of product in sku_detail Function to specify the dataset from which the data is taken AS is the alias of sku_detail AS is the alias of order_detail Limit the output. 1 means it gives the highest transaction value as it only presents the first row.
  • 18. Mobiles and tablets are categories with the highest total transaction value in 2022. Its total transaction is 918,451,576 Result
  • 19. 3. Compare the transaction value for each category in 2021 with those in 2022. Identify which category that showed an increase, and which category experienced a decrease in the value of transaction. Use is_valid = 1 to filter the data. Source table: order_detail, sku_detail. -- The comparison of transactions from each category in 2021 and 2022 SELECT category, SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2021-01-01' AND '2021-12-31' THEN od.after_discount END) total_sales_2021, -- CASE WHEN is the alternative function of IF-ELSE. If the data falls within the range of dates above, then there will be value after_discount. END function is added because if the data falls outside the range of dates above, then there will be no value after_discount. SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01' AND '2022-12-31' THEN od.after_discount END) total_sales_2022 FROM order_detail AS od LEFT JOIN sku_detail AS sd ON sd.id = od.sku_id -- Left join means returning all records from order_detail and the matched records from the sku_detail. WHERE is_valid = 1 GROUP BY 1 ORDER BY 2 DESC Query to take the data from the database and present the result The category of product in sku_detail AS is the alias of order_detail Function to filter the data Group by category Orders the result in descending form or from highest to the lowest. 2 is the sum after_discount Function to specify the dataset from which the data is taken
  • 20. -- Categories that show growth and categories that show slump WITH full_transaction as ( -- In this part, the WITH function is added. It is because, in this part, there are some conditional functions. WITH helps to define the first functions before reading the main queries. SELECT category, SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2021-01-01' AND '2021-12-31' THEN od.after_discount END) total_sales_2021, SUM(CASE WHEN to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01' AND '2022-12-31' THEN od.after_discount END) total_sales_2022 -- CASE WHEN is the alternative function of IF-ELSE. If the data falls within the range of dates above, then there will be value after_discount. END function is added because if the data falls outside the range of dates above, then there will be no value after_discount. FROM order_detail AS od LEFT JOIN sku_detail AS sd ON sd.id = od.sku_id WHERE is_valid = 1 GROUP BY 1 ORDER BY 2 DESC ) AS is the alias of order_detail Left join means returning all records from order_detail and the matched records from the sku_detail. Function to filter the data Orders the result in descending form or from highest to the lowest. 2 is the sum after_discount Function to specify the dataset from which the data is taken
  • 21. SELECT full_transaction.*, total_sales_2022 - total_sales_2021 AS growth_value -- The star symbol means that all columns in full_transaction are retrieved. Then create one column where total_sales_2022 is minus by total_sales_2021. The result will be known as growth_value. FROM full_transaction ORDER BY 4 DESC Function to specify the dataset from which the data is taken
  • 22. Result The comparison of transactions from each category in 2021 and 2022
  • 23. Result Categories that show increase and categories that show decrease. Decrease is shown by minus in the growth_value.
  • 24. 4. Identify the top 5 most popular methods of payment used in 2022 (based on total unique order) Use is_valid = 1 to filter the data. Source table: order_detail, payment_method. SELECT payment_method, COUNT (DISTINCT od.id) AS total_payment --COUNT is used because we want to count the number of unique orders. As we need to count total orders, we need to implement DISTINCT. When we use DISTINCT, although there are 5 records, we can identify that it is actually one transaction. FROM order_detail AS od LEFT JOIN payment_detail AS pd ON pd.id = od.payment_id -- Left join means returning all records from order_detail and the matched records from the payment_detail. WHERE EXTRACT (Year FROM order_date) = 2022 AND is_valid = 1 GROUP BY 1 ORDER BY 2 DESC LIMIT 5 Function to specify the dataset from which the data is taken Function to filter the data Group by payment method Limit the output. 5 means it gives 5 most used payment methods which are located in the 5 first rows.
  • 25. Result 5 most popular payment methods in 2022
  • 26. 5. Sort the 5 products based on their value of transactions: Samsung, Apple, Sony, Huawei, Lenovo. Use is_valid = 1 to filter the data. Source table: order_detail, payment_method. WITH full_transaction AS ( SELECT CASE WHEN (sku_name) like '%samsung%' THEN 'Samsung' WHEN (sku_name) LIKE '%apple%' THEN 'Apple' WHEN (sku_name) LIKE '%iphone%' THEN 'Apple' WHEN (sku_name) LIKE '%imac%' THEN 'Apple' WHEN (sku_name) LIKE '%macbook%' THEN 'Apple' WHEN (sku_name) LIKE '%sony%' THEN 'Sonny' WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei' WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei' WHEN (sku_name) LIKE '%lenovo%' THEN 'Lenovo' END product_name, SUM(after_discount) total_sales FROM order_detail AS od LEFT JOIN sku_detail as sd ON sd.id = od.sku_id WHERE to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01' AND '2022-12-31' AND is_valid = 1 GROUP BY 1 ) SELECT full_transaction.* FROM full_transaction WHERE product_name NOTNULL ORDER BY 2 DESC *Syntax explanation is on the next page
  • 27. Syntax Explanation WITH full_transaction AS ( SELECT CASE WHEN (sku_name) LIKE '%samsung%' THEN 'Samsung' WHEN (sku_name) LIKE '%apple%' THEN 'Apple' WHEN (sku_name) LIKE '%iphone%' THEN 'Apple' WHEN (sku_name) LIKE '%imac%' THEN 'Apple' WHEN (sku_name) LIKE '%macbook%' THEN 'Apple' WHEN (sku_name) LIKE '%sony%' THEN 'Sonny' WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei' WHEN (sku_name) LIKE '%huawei%' THEN 'Huawei' WHEN (sku_name) LIKE '%lenovo%' THEN 'Lenovo’ -- Regular expression function is used to identify the data text, for example, Samsung. The LIKE function is also utilized as it has the meaning of “similar with”. There is a % symbol on both sides of Samsung, which has a function to identify any string that contains “Samsung” word. END product_name, SUM(after_discount) total_sales FROM order_detail AS od LEFT JOIN sku_detail as sd ON sd.id = od.sku_id WHERE to_char (order_date,'yyyy-mm-dd') BETWEEN '2022-01-01' AND '2022-12-31' AND is_valid = 1 GROUP BY 1 ) Function to specify the dataset from which the data is taken Function to filter the data
  • 28. SELECT full_transaction.* -- The star symbol means that all columns in full-transaction are retrieved FROM full_transaction WHERE product_name NOTNULL -- The second temporary table aims to drop NOTNULL ORDER BY 2 DESC 2 means product_name and total_sales. DESC means sort from the highest to the lowest
  • 29. Result Samsung is the most popular product name as its total sales reach 97,552,288
  • 30. Follow me! Instagram : elyadawigatip Twitter : @EliNoBishamon LinkedIn : https://www.linkedin.com/in/elyada- wigati-pramaresti-1a2387170/ Bootcamp Data Analysis by @myskill.id