├── .gitattributes ├── 01.Churn Rate.sql ├── 02. Marketing Click Through Rate Analytics.sql ├── 03. Population_queries_II.sql ├── 04.Startups.sql ├── 05. population_queries.sql ├── 06. RPA_FRAUD_DETECTION.sql ├── 07. RPA-Customer-Segmentation.sql ├── 08. Davie's Burgers Subway Ad.sql ├── README.md └── _config.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sql linguist-detectable=true 2 | *.tsql linguist-detectable=false 3 | -------------------------------------------------------------------------------- /01.Churn Rate.sql: -------------------------------------------------------------------------------- 1 | WITH months AS ( 2 | SELECT '2017-01-01' AS 'First_Day', 3 | '2017-01-31' AS 'Last_Day' 4 | UNION 5 | SELECT '2017-02-01' AS 'First_Day', 6 | '2017-02-31' AS 'Last_Day' 7 | UNION 8 | SELECT '2017-03-01' AS 'First_Day', 9 | '2017-03-31' AS 'Last_Day' 10 | ), 11 | cross_join AS ( 12 | SELECT * 13 | FROM subscriptions 14 | CROSS JOIN months 15 | ), 16 | status AS( 17 | SELECT id, 18 | First_Day AS month, 19 | CASE 20 | WHEN subscription_start < 'First Day' AND 21 | segment = 87 THEN 1 22 | ELSE 0 23 | END AS 'is_active_87', 24 | CASE 25 | WHEN subscription_start < 'First Day' AND 26 | segment = 30 THEN 1 27 | ELSE 0 28 | END AS 'is_active_30', 29 | CASE 30 | WHEN (subscription_end BETWEEN First_Day AND Last_Day) AND 31 | segment = 87 THEN 1 32 | ELSE 0 33 | END AS 'is_canceled_87', 34 | CASE 35 | WHEN (subscription_end BETWEEN First_Day AND Last_Day) AND 36 | segment = 30 THEN 1 37 | ELSE 0 38 | END AS 'is_canceled_30' 39 | FROM cross_join 40 | ), 41 | status_aggregate AS( 42 | SELECT 43 | month, 44 | SUM(is_active_87) AS sum_active_87, 45 | SUM(is_active_30) AS sum_active_30, 46 | SUM(is_canceled_87) AS sum_canceled_87, 47 | SUM(is_canceled_30) AS sum_canceled_30 48 | FROM status 49 | GROUP BY month 50 | ) 51 | SELECT 52 | month, 53 | 100.00 * sum_canceled_87 / sum_active_87 AS 'Churn Rate 87 Group', 54 | 100.00 * sum_canceled_30 / sum_active_30 AS 'Churn Rate 30 Group' 55 | FROM status_aggregate; 56 | -------------------------------------------------------------------------------- /02. Marketing Click Through Rate Analytics.sql: -------------------------------------------------------------------------------- 1 | SELECT 2 | COUNT(DISTINCT utm_campaign) AS 'Campaigns', 3 | COUNT(DISTINCT utm_source) AS 'Sources' 4 | FROM page_visits; 5 | 6 | 7 | SELECT 8 | DISTINCT page_name 9 | FROM page_visits; 10 | 11 | 12 | WITH first_touch AS ( 13 | SELECT user_id, 14 | MIN(timestamp) as first_touch_at 15 | FROM page_visits 16 | GROUP BY user_id) 17 | SELECT 18 | pv.utm_campaign, 19 | COUNT(*) AS 'Campaign First Touch CTR' 20 | FROM first_touch AS ft 21 | JOIN page_visits AS pv 22 | ON ft.user_id = pv.user_id 23 | AND ft.first_touch_at = pv.timestamp 24 | GROUP BY 25 | pv.utm_campaign 26 | ORDER BY 27 | 2 DESC; 28 | 29 | 30 | WITH last_touch AS ( 31 | SELECT user_id, 32 | MAX(timestamp) as last_touch_at 33 | FROM page_visits 34 | GROUP BY user_id) 35 | SELECT 36 | pv.utm_campaign, 37 | COUNT(*) AS 'Campaign Last Touch CTR' 38 | FROM last_touch AS lt 39 | JOIN page_visits AS pv 40 | ON lt.user_id = pv.user_id 41 | AND lt.last_touch_at = pv.timestamp 42 | GROUP BY 43 | pv.utm_campaign 44 | ORDER BY 45 | 2 DESC; 46 | 47 | 48 | SELECT 49 | COUNT(DISTINCT user_id) AS 'Purchaser' 50 | FROM page_visits 51 | WHERE page_name = '4 - purchase'; 52 | 53 | 54 | 55 | WITH last_touch AS ( 56 | SELECT user_id, 57 | MAX(timestamp) as last_touch_at 58 | FROM page_visits 59 | GROUP BY user_id) 60 | SELECT 61 | pv.utm_campaign, 62 | COUNT(*) AS 'Campaign Leading purchase CTR' 63 | FROM last_touch AS lt 64 | JOIN page_visits AS pv 65 | ON lt.user_id = pv.user_id 66 | AND lt.last_touch_at = pv.timestamp 67 | WHERE 68 | page_name = '4 - purchase' 69 | GROUP BY 70 | pv.utm_campaign 71 | ORDER BY 72 | 2 DESC; 73 | -------------------------------------------------------------------------------- /03. Population_queries_II.sql: -------------------------------------------------------------------------------- 1 | SELECT COUNT(*) AS 'From Africa' 2 | FROM countries 3 | WHERE continent = 'Africa'; 4 | 5 | SELECT SUM(population_years.population) AS 'Oceania pop. 2005' 6 | FROM countries 7 | JOIN population_years 8 | ON countries.id = population_years.country_id 9 | WHERE population_years.year = 2005 AND 10 | countries.continent = 'Oceania' 11 | GROUP BY countries.continent; 12 | 13 | SELECT AVG(population_years.population) AS 'South America AVG pop. 2003' 14 | FROM countries 15 | JOIN population_years 16 | ON countries.id = population_years.country_id 17 | WHERE population_years.year = 2003 AND 18 | countries.continent = 'South America' 19 | GROUP BY countries.continent; 20 | 21 | SELECT countries.name AS 'Country', MIN(population_years.population) AS 'Lowest pop. Country 2007' 22 | FROM countries 23 | JOIN population_years 24 | ON countries.id = population_years.country_id 25 | WHERE population_years.year = 2007; 26 | 27 | SELECT countries.name AS 'Country', ROUND(AVG(population_years.population),2) AS 'AVG Poland POP. during Covered Timeperiod' 28 | FROM countries 29 | JOIN population_years 30 | ON countries.id = population_years.country_id 31 | WHERE countries.name = 'Poland'; 32 | 33 | SELECT COUNT(*) AS 'Countries Having The In Name' 34 | FROM countries 35 | WHERE name LIKE '% The%'; 36 | 37 | SELECT countries.continent AS 'Continent', ROUND(SUM(population_years.population),2) AS 'Pop By Continent-2010' 38 | FROM countries 39 | JOIN population_years 40 | ON countries.id = population_years.country_id 41 | WHERE population_years.year = 2010 42 | GROUP BY countries.continent 43 | ORDER BY 2 DESC ; 44 | -------------------------------------------------------------------------------- /04.Startups.sql: -------------------------------------------------------------------------------- 1 | SELECT COUNT(DISTINCT(name)) AS 'Total No. of Companies' 2 | FROM startups; 3 | 4 | SELECT SUM(valuation) AS 'Total Valuation' 5 | FROM startups; 6 | 7 | SELECT MAX(raised) AS 'Highest Amount Raised' 8 | FROM startups 9 | WHERE stage = 'Seed'; 10 | 11 | SELECT MIN(founded) AS 'Oldest Founding Year' 12 | FROM startups; 13 | 14 | SELECT AVG(valuation) 15 | FROM startups; 16 | 17 | 18 | 19 | 20 | 21 | SELECT category, ROUND(AVG(valuation),2) AS 'Mean Valuation' 22 | FROM startups 23 | WHERE category IS NOT NULL 24 | GROUP BY category 25 | ORDER BY ROUND(AVG(valuation),2) DESC ; 26 | 27 | 28 | 29 | 30 | 31 | SELECT category, COUNT(name) AS 'Companies' 32 | FROM startups 33 | GROUP BY category 34 | ORDER BY COUNT(name) DESC; 35 | 36 | SELECT category, COUNT(name) AS 'Competitive Companies' 37 | FROM startups 38 | GROUP BY category 39 | HAVING COUNT(name) > 3 40 | ORDER BY COUNT(name) DESC; 41 | 42 | 43 | 44 | 45 | SELECT location, ROUND(AVG(employees), 0) AS 'Average Employee Count' 46 | FROM startups 47 | GROUP BY location 48 | ORDER BY AVG(employees) DESC; 49 | 50 | SELECT location, ROUND(AVG(employees), 0) AS 'Average Employee Count' 51 | FROM startups 52 | GROUP BY location 53 | HAVING ROUND(AVG(employees), 0) > 500 54 | ORDER BY AVG(employees) DESC; 55 | -------------------------------------------------------------------------------- /05. population_queries.sql: -------------------------------------------------------------------------------- 1 | -- This is the first query: 2 | 3 | SELECT DISTINCT year from population_years; 4 | 5 | -- Adding additional queries below: 6 | SELECT country, population 7 | FROM population_years 8 | WHERE country = 'Gabon' 9 | ORDER BY population DESC 10 | LIMIT 1; 11 | 12 | SELECT * 13 | FROM population_years 14 | WHERE year = 2005 15 | AND population IS NOT NULL 16 | ORDER BY population 17 | LIMIT 10; 18 | 19 | SELECT * 20 | FROM population_years 21 | WHERE population > 100 AND 22 | year = 2010 23 | ORDER BY population DESC; 24 | 25 | SELECT DISTINCT country 26 | FROM population_years 27 | WHERE country LIKE '%Islands%'; 28 | 29 | SELECT * 30 | FROM population_years 31 | WHERE year = 2000 AND 32 | country = 'Indonesia'; 33 | 34 | 35 | SELECT * 36 | FROM population_years 37 | WHERE year = 2010 AND 38 | country = 'Indonesia'; 39 | 40 | -------------------------------------------------------------------------------- /06. RPA_FRAUD_DETECTION.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM transaction_data 3 | LIMIT 10; 4 | 5 | SELECT full_name, email 6 | FROM transaction_data 7 | WHERE zip = 20252; 8 | 9 | 10 | SELECT full_name, email 11 | FROM transaction_data 12 | WHERE full_name LIKE '% der %' OR 13 | full_name = 'Art Vandelay'; 14 | 15 | SELECT ip_address, email 16 | FROM transaction_data 17 | WHERE ip_address LIKE '10.%'; 18 | 19 | SELECT email 20 | FROM transaction_data 21 | WHERE email LIKE '%temp_email.com'; 22 | 23 | SELECT * 24 | FROM transaction_data 25 | WHERE ip_address LIKE '120.%' AND 26 | full_name LIKE 'John%'; 27 | -------------------------------------------------------------------------------- /07. RPA-Customer-Segmentation.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM users 3 | LIMIT 20; 4 | 5 | SELECT email, birthday 6 | FROM users 7 | WHERE birthday BETWEEN '1980-01-01' AND '1989-12-31' 8 | ORDER BY birthday; 9 | 10 | SELECT email, created_at 11 | FROM users 12 | WHERE created_at < '2017-05-01' 13 | ORDER BY created_at; 14 | 15 | SELECT email 16 | FROM users 17 | WHERE test = 'bears'; 18 | 19 | SELECT email 20 | FROM users 21 | WHERE campaign LIKE 'BBB%'; 22 | 23 | SELECT email 24 | FROM users 25 | WHERE campaign LIKE '%-2'; 26 | 27 | 28 | SELECT email 29 | FROM users 30 | WHERE campaign IS NOT NULL AND 31 | test IS NOT NULL; 32 | 33 | -------------------------------------------------------------------------------- /08. Davie's Burgers Subway Ad.sql: -------------------------------------------------------------------------------- 1 | SELECT * 2 | FROM orders 3 | LIMIT 10; 4 | 5 | SELECT DISTINCT order_date 6 | FROM orders 7 | ORDER BY order_date DESC; 8 | 9 | SELECT DISTINCT special_instructions 10 | FROM orders 11 | WHERE special_instructions IS NOT NULL 12 | ORDER BY special_instructions 13 | LIMIT 20; 14 | 15 | SELECT id AS '#', special_instructions AS 'Notes' 16 | FROM orders 17 | WHERE special_instructions LIKE '%sauce%'; 18 | 19 | SELECT id AS '#', special_instructions AS 'Notes' 20 | FROM orders 21 | WHERE special_instructions LIKE '%door%'; 22 | 23 | SELECT id AS '#', special_instructions AS 'Notes' 24 | FROM orders 25 | WHERE special_instructions LIKE '%box%'; 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
Author   
5 | 6 | 7 | 8 | # *01. Churn Rates Calculation* 9 | 10 | ## Project Goals 11 | Four months into launching Codeflix, management asks to look into subscription churn rate. It’s early on in the business and people are excited to know how the company is doing. The marketing department is particularly interested in how the churn compares between two segments of users. They provide a dataset containing subscription data for users who were acquired through two distinct channels. 12 | Codeflix requires a minimum subscription length of 31 days, so user can never start and end their subscription in the same month. 13 | - Calculation of the churn rates for the two segments over the three month period. Which segment has a lower churn rate? 14 | 15 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/01.Churn%20Rate.sql) 16 | 17 |


18 | 19 | # *02. Marketing Click Through Rate Analytics* 20 | 21 | 22 | ## Project Goals 23 | CoolTShirts sells shirts of all kinds, as long as they are T-shaped and cool. Recently, CTS started a few marketing campaigns to increase website visits and purchases. Using touch attribution, they’d like to map their customers’ journey: from initial visit to purchase. They can use that information to optimize their marketing campaigns.I tried to answer following questions with sql query. 24 | 25 | - How many campaigns and sources does CoolTShirts use? Which source is used for each campaign? 26 | - What pages are on the CoolTShirts website? 27 | - How many first touches is each campaign responsible for? 28 | - How many last touches is each campaign responsible for? 29 | - How many visitors make a purchase? 30 | - How many last touches on the purchase page is each campaign responsible for? 31 | - CoolTShirts can re-invest in 5 campaigns. Given your findings in the project, which should they pick and why? 32 | 33 | 34 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/02.%20Marketing%20Click%20Through%20Rate%20Analytics.sql) 35 | 36 |


37 | 38 | # *03. World Populations II* 39 | 40 | 41 | ## Project Goals 42 | Here I worked on a dataset of world population by country data from recent years. Tried to write queries to retrieve interesting data and answer a set of specific questions. 43 | 44 | - How many entries in the countries table are from Africa? 45 | - What was the total population of the continent of Oceania in 2005? 46 | - What is the average population of countries in South America in 2003? 47 | - What country had the smallest population in 2007? 48 | - What is the average population of Poland during the time period covered by this dataset? 49 | - How many countries have the word “The” in their name? 50 | - What was the total population of each continent in 2010? 51 | 52 | 53 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/03.%20Population_queries_II.sql) 54 | 55 | 56 |


57 | 58 | # *04. Trends in Startups* 59 | 60 | 61 | ## Project Goals 62 | The task was to write an article on the rising trends in the startup world. To get started with the research, I started with a project.sqlite file that contains a table called startups. It is a portfolio of some of the biggest names in the industry. Data collected from [TechCrunch](https://techcrunch.com/). 63 | 64 | - Calculating total number of companies in the table. 65 | - We want to know the total value of all companies in this table. 66 | - What is the highest amount raised by a startup at 'Seed' Stage? 67 | - In what year was the oldest company on the list founded? 68 | - Let's find out the valuations among different sectors: 69 | - Average valuation, in each category. 70 | - What are the most competitive markets? 71 | - What are the most competitive markets? 72 | - Let's see if there's a difference in startups sizes among different locations: 73 | - What is the average size of a startup in each location, with average sizes above 500? 74 | 75 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/04.Startups.sql) 76 | 77 |


78 | 79 | # *05. World Populations SQL I* 80 | 81 | 82 | ## Project Goals 83 | Here is a dataset of world population by country data from recent years. I tried to answer following questions with sql query. 84 | 85 | - What years are covered by the dataset? 86 | - What is the largest population size for Gabon in this dataset? 87 | - What were the 10 lowest population countries in 2005? 88 | - What are all the distinct countries with a population of over 100 million in the year 2010? 89 | - How many countries in this dataset have the word “Islands” in their name? 90 | - What is the difference in population between 2000 and 2010 in Indonesia? 91 | 92 | 93 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository) 94 | 95 |


96 | 97 | # *06. RPA Fraud Detection* 98 | 99 | 100 | ## Project Goals 101 | Reputable Product Agency (RPA) has started receiving complaints from their credit card processor about fraudulent transactions. 102 | I tried to answer following assumptions with sql query. 103 | 104 | - The finance department noted that some of the fraudulent transactions were recorded as coming from Smokey Bear’s zip code (20252). 105 | - Finance has also noticed a number of pseudonyms associated with fraudulent transactions. 106 | The fraudsters thought it would be funny to use ‘Art Vandelay’ for their full name or add a ‘der’ for their middle name. 107 | - There are some irregularities in the IP addresses where transactions are originating from. 108 | For example, any IP address beginning with ‘10.’ is reserved for internal use. 109 | - Users are making fraudulent transactions using a temporary email address service. These services provide a short-lived email that can be verified and then self-destructs. 110 | - The finance department is looking for a specific transaction. They know that the transaction occurred from an ip address starting with ‘120.’ and their full name starts with ‘John’. 111 | 112 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/06.%20RPA_FRAUD_DETECTION.sql) 113 | 114 |


115 | 116 | # *07. RPA Customer Segmentation* 117 | 118 | 119 | ## Project Goals 120 | The marketing department of Reputable Product Agency (RPA) is looking to segment the company users by a number of different criteria. In this context, a segment is a subset of users that meet different conditions. Segments are used to send marketing campaigns to users who meet specific criteria or to measure the performance of specific marketing campaigns. I tried to retrieve data under following circumstances with sql query. 121 | 122 | - The marketing department wants to send a Born in the ‘80s email to the appropriate users. 123 | - We are interested in the cohort of users that signed up prior to May 2017. 124 | - There was an A/B test performed on users that used cute animal clipart to encourage users to sign up. We’d like to see how the group that was shown ‘bears’ is performing. 125 | - A total of 4 advertising campaigns were run over this period. There were two sets of ad copy (set 1 and set 2) and both were run on two search engine sites (AAA and BBB). The resulting campaign values are: 126 | 127 | - AAA-1 128 | - AAA-2 129 | - BBB-1 130 | - BBB-2 131 | 132 | Lets find all the emails of all users who received a campaign on website BBB. 133 | - Find all the emails of all users who received ad copy 2 in their campaign. 134 | - Find the emails for all users who received both a campaign and a test. These users will have non-empty entries in the campaign and test columns. 135 | 136 | 137 | 👈🏻*Click Here* [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/07.%20RPA-Customer-Segmentation.sql) 138 | 139 |


140 | 141 | # *08. Davie's Burgers Subway Ad* 142 | 143 | 144 | ## Project Goals 145 | 'Davie’s Burgers' the restaurant business has been booming and it is now looking to place a catchy advertisement in the local subway station. Lets help them dig into their orders table to see if there is anything interesting in there for a funny tagline! 146 | 147 | - How recent is this data? 148 | - The special_instructions column stores the data where Davie’s Burgers customers leave a note for the kitchen or the delivery. Lets see the result to 20 rows. 149 | - Let’s search for special instructions that have the word ‘sauce’. Are there any funny or interesting ones? 150 | - Let’s search for special instructions that have the word ‘door’. Any funny or interesting ones? 151 | - Let’s search for special instructions that have the word ‘box’. Any funny or interesting ones? 152 | - Some of these are marketing gold! But what are their order numbers? 153 | 154 | 155 | 156 | 👈🏻**Click Here** [SQL](https://github.com/Emon-ProCoder7/sql-Command-Repository/blob/master/08.%20Davie's%20Burgers%20Subway%20Ad.sql) 157 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect --------------------------------------------------------------------------------