Created
August 5, 2023 20:50
-
-
Save nagappankv/5c5b637516fe725e49eac365a3b8d9fe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Which are the top 5 products by sales? | |
SELECT | |
`Product Name`, | |
SUM(`Sales`) AS `Total Sales` | |
FROM | |
Superstore | |
GROUP BY | |
`Product Name` | |
ORDER BY | |
`Total Sales` DESC | |
LIMIT 5; | |
-- Which are the top 5 products by profit? | |
SELECT | |
`Product Name`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`Product Name` | |
ORDER BY | |
`Total Profit` DESC | |
LIMIT 5; | |
-- What is the distribution of sales across different regions? | |
SELECT | |
`Region`, | |
SUM(`Sales`) AS `Total Sales` | |
FROM | |
Superstore | |
GROUP BY | |
`Region`; | |
-- What is the distribution of profit across different regions? | |
SELECT | |
`Region`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`Region`; | |
-- What is the trend of sales and profit over time? | |
-- Note: This requires a date field and SQLite does not directly support extracting YEAR and MONTH from a date. | |
-- However, you can create a new column in Excel with YEAR and MONTH before uploading to SQLite and use that column here. | |
-- Who are the top 5 customers by sales? | |
SELECT | |
`Customer ID`, | |
SUM(`Sales`) AS `Total Sales` | |
FROM | |
Superstore | |
GROUP BY | |
`Customer ID` | |
ORDER BY | |
`Total Sales` DESC | |
LIMIT 5; | |
-- Who are the top 5 customers by profit? | |
SELECT | |
`Customer ID`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`Customer ID` | |
ORDER BY | |
`Total Profit` DESC | |
LIMIT 5; | |
-- How do sales and profit vary by sub-category? | |
SELECT | |
`Sub-Category`, | |
SUM(`Sales`) AS `Total Sales`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`Sub-Category`; | |
-- Are there any particular months where sales and profit spike? | |
-- Note: This requires a date field and SQLite does not directly support extracting YEAR and MONTH from a date. | |
-- However, you can create a new column in Excel with YEAR and MONTH before uploading to SQLite and use that column here. | |
-- What are the top 5 states in terms of sales and profit? | |
SELECT | |
`State`, | |
SUM(`Sales`) AS `Total Sales`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`State` | |
ORDER BY | |
`Total Sales` DESC, | |
`Total Profit` DESC | |
LIMIT 5; | |
-- How are sales and profit distributed among different segments? | |
SELECT | |
`Segment`, | |
SUM(`Sales`) AS `Total Sales`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`Segment`; | |
-- How does the profit ratio vary by category and sub-category? | |
SELECT | |
`Category`, | |
`Sub-Category`, | |
SUM(`Profit`) / SUM(`Sales`) AS `Profit Ratio` | |
FROM | |
Superstore | |
GROUP BY | |
`Category`, | |
`Sub-Category`; | |
-- Are there certain times of the year when discounts are more prevalent? | |
-- Note: This requires a date field and SQLite does not directly support extracting YEAR and MONTH from a date. | |
-- However, you can create a new column in Excel with YEAR and MONTH before uploading to SQLite and use that column here. | |
-- What is the average quantity sold by category? | |
SELECT | |
`Category`, | |
AVG(`Quantity`) AS `Average Quantity` | |
FROM | |
Superstore | |
GROUP BY | |
`Category`; | |
-- What are the top 5 most sold products in each category? | |
-- Note: This is more complex and might be better handled with multiple queries or by using a tool that supports window functions. | |
-- What is the sales and profit distribution across different product IDs? | |
SELECT | |
`Product ID`, | |
SUM(`Sales`) AS `Total Sales`, | |
SUM(`Profit`) AS `Total Profit` | |
FROM | |
Superstore | |
GROUP BY | |
`Product ID`; | |
-- How do discounts impact sales and profit? | |
-- Note: This requires case statements or subqueries and might be better handled in a tool that supports these features. | |
-- Who are the most profitable customers in each segment? | |
-- Note: This is more complex and might be better handled with multiple queries or by using a tool that supports window functions. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment