SlideShare a Scribd company logo
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 R
Casper Crause
 
paytm_mall_epurchase_data data analysis.
paytm_mall_epurchase_data data analysis.paytm_mall_epurchase_data data analysis.
paytm_mall_epurchase_data data analysis.
ankita222345
 
Data Warehousing
Data WarehousingData Warehousing
Set Analyse OK.pdf
Set Analyse OK.pdfSet Analyse OK.pdf
Set Analyse OK.pdf
qlik2learn2024
 
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
faithxdunce63732
 
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
Maria Colgan
 
MSA_8110_Final_Project
MSA_8110_Final_ProjectMSA_8110_Final_Project
MSA_8110_Final_Project
Christina Pemberton
 
Technical architecture for order management
Technical architecture for order managementTechnical architecture for order management
Technical architecture for order management
Mohit kumar Gupta
 
Check printing in_r12
Check printing in_r12Check printing in_r12
Check printing in_r12
Rajesh 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.pdf
Eleonora Ciceri
 
Sqlserver interview questions
Sqlserver interview questionsSqlserver interview questions
Sqlserver interview questions
Taj Basha
 
Project report aditi paul1
Project report aditi paul1Project report aditi paul1
Project report aditi paul1
guest9529cb
 
AIRBNB DATA WAREHOUSE & GRAPH DATABASE
AIRBNB DATA WAREHOUSE & GRAPH DATABASEAIRBNB DATA WAREHOUSE & GRAPH DATABASE
AIRBNB DATA WAREHOUSE & GRAPH DATABASE
Sagar 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 2018
Adilson Mendonca
 
Part3 Explain the Explain Plan
Part3 Explain the Explain PlanPart3 Explain the Explain Plan
Part3 Explain the Explain Plan
Maria Colgan
 
Dfd2
Dfd2Dfd2
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
Pridhvi Kodamasimham
 
Dwbi Project
Dwbi ProjectDwbi Project
Dwbi Project
Sonali Gupta
 
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
honey725342
 
Simple Spreadsheet Tips
Simple Spreadsheet TipsSimple Spreadsheet Tips
Simple Spreadsheet Tips
Inside Access
 

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
 
paytm_mall_epurchase_data data analysis.
paytm_mall_epurchase_data data analysis.paytm_mall_epurchase_data data analysis.
paytm_mall_epurchase_data data analysis.
 
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
 

More from Elyada Wigati Pramaresti

Final Project Data Visualization - Elyada Wigati
Final Project Data Visualization - Elyada WigatiFinal Project Data Visualization - Elyada Wigati
Final Project Data Visualization - Elyada Wigati
Elyada Wigati Pramaresti
 
SQL Basic Clause - Portfolio.pptx
SQL Basic Clause - Portfolio.pptxSQL Basic Clause - Portfolio.pptx
SQL Basic Clause - Portfolio.pptx
Elyada Wigati Pramaresti
 
Working with Google Sheet - Portfolio.pptx
Working with Google Sheet - Portfolio.pptxWorking with Google Sheet - Portfolio.pptx
Working with Google Sheet - Portfolio.pptx
Elyada Wigati Pramaresti
 
Intro to Statistics.pptx
Intro to Statistics.pptxIntro to Statistics.pptx
Intro to Statistics.pptx
Elyada Wigati Pramaresti
 
Improvement as Data Analyst.pptx
Improvement as Data Analyst.pptxImprovement as Data Analyst.pptx
Improvement as Data Analyst.pptx
Elyada Wigati Pramaresti
 
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
Elyada Wigati Pramaresti
 
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
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

Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Aggregage
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
Sm321
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
kuntobimo2016
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
Social Samosa
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
nuttdpt
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
v7oacc3l
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
aqzctr7x
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
Social Samosa
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
jerlynmaetalle
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
AndrzejJarynowski
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
apvysm8
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
mbawufebxi
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
bopyb
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
sameer shah
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
vikram sood
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
Roger Valdez
 

Recently uploaded (20)

Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
Beyond the Basics of A/B Tests: Highly Innovative Experimentation Tactics You...
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
Challenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more importantChallenges of Nation Building-1.pptx with more important
Challenges of Nation Building-1.pptx with more important
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023State of Artificial intelligence Report 2023
State of Artificial intelligence Report 2023
 
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
4th Modern Marketing Reckoner by MMA Global India & Group M: 60+ experts on W...
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
一比一原版(UCSF文凭证书)旧金山分校毕业证如何办理
 
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
在线办理(英国UCA毕业证书)创意艺术大学毕业证在读证明一模一样
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
The Ipsos - AI - Monitor 2024 Report.pdf
The  Ipsos - AI - Monitor 2024 Report.pdfThe  Ipsos - AI - Monitor 2024 Report.pdf
The Ipsos - AI - Monitor 2024 Report.pdf
 
Influence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business PlanInfluence of Marketing Strategy and Market Competition on Business Plan
Influence of Marketing Strategy and Market Competition on Business Plan
 
Intelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicineIntelligence supported media monitoring in veterinary medicine
Intelligence supported media monitoring in veterinary medicine
 
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
办(uts毕业证书)悉尼科技大学毕业证学历证书原版一模一样
 
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
一比一原版(Bradford毕业证书)布拉德福德大学毕业证如何办理
 
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
一比一原版(GWU,GW文凭证书)乔治·华盛顿大学毕业证如何办理
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
STATATHON: Unleashing the Power of Statistics in a 48-Hour Knowledge Extravag...
 
Global Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headedGlobal Situational Awareness of A.I. and where its headed
Global Situational Awareness of A.I. and where its headed
 
Everything you wanted to know about LIHTC
Everything you wanted to know about LIHTCEverything you wanted to know about LIHTC
Everything you wanted to know about LIHTC
 

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