├── Chicago Taxi Trips ├── Coffee Equipment Store Database & Stats ├── Exploring Netflix Data Using PostgreSQL ├── Customer Online Spending Habits ├── Famous Singers Database & Stats ├── README.md ├── Stack Overflow Questions & Answers ├── Digital Media Store Data Analysis ├── Customer & Order Analytics ├── Spotify Top Songs 2021 Data Analysis ├── City Bike Lane Data ├── Predicting Book Ratings └── Country Populations Database & Stats /Chicago Taxi Trips: -------------------------------------------------------------------------------- 1 | --Dataset: Chicago Taxi Trips from BigQuery 2 | --Source: https://www.kaggle.com/datasets/chicago/chicago-taxi-trips-bq 3 | --Queried using: Kaggle Notebook 4 | 5 | # Display the rolling average of the daily number of taxi trips 6 | avg_num_trips_query = """ 7 | WITH trips_by_day AS 8 | ( 9 | SELECT DATE(trip_start_timestamp) AS trip_date, 10 | COUNT(*) as num_trips 11 | FROM `bigquery-public-data.chicago_taxi_trips.taxi_trips` 12 | WHERE trip_start_timestamp >= '2016-01-01' AND trip_start_timestamp < '2018-01-01' 13 | GROUP BY trip_date 14 | ORDER BY trip_date 15 | ) 16 | SELECT trip_date, 17 | AVG(num_trips) 18 | OVER ( 19 | ORDER BY trip_date 20 | ROWS BETWEEN 15 PRECEDING AND 15 FOLLOWING 21 | ) AS avg_num_trips 22 | FROM trips_by_day 23 | """ 24 | -------------------------------------------------------------------------------- /Coffee Equipment Store Database & Stats: -------------------------------------------------------------------------------- 1 | --Create a coffee equipment store 2 | CREATE TABLE storefront (id INTEGER PRIMARY KEY, name TEXT, aisle INTEGER, price INTEGER, quantity INTEGER); 3 | 4 | INSERT INTO storefront VALUES (1, "large mug", 1, 14, 20); 5 | INSERT INTO storefront VALUES (2, "V60 filters", 2, 5, 100); 6 | INSERT INTO storefront VALUES (3, "grinder", 3, 99, 5); 7 | INSERT INTO storefront VALUES (4, "V60", 2, 30, 10); 8 | INSERT INTO storefront VALUES (5, "kalita", 2, 25, 10); 9 | INSERT INTO storefront VALUES (6, "kalita filters", 2, 5, 100); 10 | INSERT INTO storefront VALUES (7, "small mug", 1, 9, 20); 11 | INSERT INTO storefront VALUES (8, "aeropress", 2, 25, 10); 12 | INSERT INTO storefront VALUES (9, "aeropress filters", 2, 5, 100); 13 | INSERT INTO storefront VALUES (10, "kettle", 3, 149, 5); 14 | INSERT INTO storefront VALUES (11, "chemex", 2, 30, 10); 15 | INSERT INTO storefront VALUES (12, "chemex filters", 2, 5, 100); 16 | INSERT INTO storefront VALUES (13, "demitasse spoon", 1, 5, 200); 17 | INSERT INTO storefront VALUES (14, "espresso machine", 3, 2000, 2); 18 | INSERT INTO storefront VALUES (15, "plates", 1, 10, 50); 19 | 20 | --Display the database ordered by price 21 | SELECT * FROM storefront 22 | ORDER BY price DESC; 23 | 24 | --What is the average price of each type of item? 25 | SELECT type, AVG(price) FROM storefront 26 | GROUP BY type 27 | ORDER BY price DESC; 28 | -------------------------------------------------------------------------------- /Exploring Netflix Data Using PostgreSQL: -------------------------------------------------------------------------------- 1 | --Join the two tables to include director data 2 | SELECT 3 | titles.show_id, 4 | titles.title, 5 | people.director, 6 | titles.release_year 7 | FROM "CharlotteChaze/BreakIntoTech"."netflix_titles_info" as titles 8 | LEFT JOIN "CharlotteChaze/BreakIntoTech"."netflix_people" as people 9 | ON titles.show_id = people.show_id; 10 | 11 | --How many movie titles (not TV shows) are there in the database? 12 | SELECT COUNT(*) AS total_movies 13 | FROM "CharlotteChaze/BreakIntoTech"."netflix_titles_info" 14 | WHERE type = 'Movie'; 15 | 16 | --When was the most recent batch of TV shows and/or movies added to the database? 17 | SELECT MAX(date_added) FROM "CharlotteChaze/BreakIntoTech"."netflix_titles_info"; 18 | 19 | --List all the movies and TV shows in alphabetical order 20 | SELECT title FROM "CharlotteChaze/BreakIntoTech"."netflix_titles_info" 21 | ORDER BY title ASC; 22 | 23 | --Who was the director for the movie Bright Star? 24 | SELECT 25 | titles.title, 26 | people.director 27 | FROM "CharlotteChaze/BreakIntoTech"."netflix_titles_info" as titles 28 | LEFT JOIN "CharlotteChaze/BreakIntoTech"."netflix_people" as people 29 | ON titles.show_id = people.show_id 30 | WHERE titles.title = 'Bright Star'; 31 | 32 | --What is the oldest movie in the database and what year was it made? 33 | SELECT title, release_year FROM "CharlotteChaze/BreakIntoTech"."netflix_titles_info" 34 | WHERE type = 'Movie' 35 | ORDER BY release_year ASC 36 | LIMIT 1; 37 | -------------------------------------------------------------------------------- /Customer Online Spending Habits: -------------------------------------------------------------------------------- 1 | -- Let's look at the orders, items sold, revenue, and profit as key performance indicators for each country. 2 | 3 | select 4 | country, 5 | count(id) as total_orders, 6 | sum(quantity) as items_sold, 7 | sum(total_revenue)::money as revenue, 8 | sum(total_profit)::money as profit 9 | from online_sales 10 | group by country 11 | order by items_sold desc; 12 | 13 | -- Let's look at the basic demographic breakdown for customers in each country. 14 | 15 | select 16 | country, 17 | gender, 18 | round(avg(age), 1) as age, 19 | round(avg(quantity), 1) as items_purchased, 20 | round(avg(total_cost), 2) as amount_spent 21 | from online_sales 22 | group by country, gender 23 | order by country, gender; 24 | 25 | -- Our customers who spend the most amount on an average order are 35-year-old females in Germany and 35-year-old males in France. 26 | -- Our customers who spend the least amount on an average order are in the United States. 27 | 28 | -- Let's look at the product categories with the most sales. 29 | 30 | select 31 | category, 32 | count(id) as orders 33 | from online_sales 34 | group by category 35 | order by orders desc; 36 | 37 | -- Our accessories account 64.6% of all our online sales. 38 | 39 | -- Let's look at a similar breakdown for the subcategories within accessories. 40 | 41 | select 42 | subcategory, 43 | count(id) as orders 44 | from online_sales 45 | where category = 'Accessories' 46 | group by subcategory 47 | order by orders desc; 48 | 49 | -- Tires and tubes account for 49.3% of all our accessories sales. 50 | -------------------------------------------------------------------------------- /Famous Singers Database & Stats: -------------------------------------------------------------------------------- 1 | --Create database of famous singers 2 | CREATE TABLE famous_singers ( 3 | id INTEGER PRIMARY KEY, 4 | name TEXT, 5 | age INTEGER); 6 | 7 | CREATE TABLE singers_birthplaces ( 8 | id INTEGER PRIMARY KEY, 9 | name TEXT); 10 | 11 | CREATE TABLE singers_spotify_performance ( 12 | id INTEGER PRIMARY KEY, 13 | monthly_listeners INTEGER, 14 | global_rank INTEGER); 15 | 16 | INSERT INTO famous_singers VALUES 17 | (1, "Taylor Swift", 32); 18 | INSERT INTO famous_singers VALUES 19 | (2, "Lady Gaga", 36); 20 | INSERT INTO famous_singers VALUES 21 | (3, "Prince", NULL); 22 | INSERT INTO famous_singers VALUES 23 | (4, "Harry Styles", 28); 24 | INSERT INTO famous_singers VALUES 25 | (5, "David Bowie", NULL); 26 | INSERT INTO famous_singers VALUES 27 | (6, "Freddie Mercury", NULL); 28 | INSERT INTO famous_singers VALUES 29 | (7, "Lizzo", 34); 30 | 31 | INSERT INTO singers_birthplaces VALUES 32 | (1, "Reading, PA"); 33 | INSERT INTO singers_birthplaces VALUES 34 | (2, "New York, NY"); 35 | INSERT INTO singers_birthplaces VALUES 36 | (3, "Minneapolis, MN"); 37 | INSERT INTO singers_birthplaces VALUES 38 | (4, "Redditch, United Kingdom"); 39 | INSERT INTO singers_birthplaces VALUES 40 | (5, "London, United Kingdom"); 41 | INSERT INTO singers_birthplaces VALUES 42 | (6, "London, United Kingdom"); 43 | INSERT INTO singers_birthplaces VALUES 44 | (7, "Detroit, MI"); 45 | 46 | INSERT INTO singers_spotify_performance VALUES 47 | (1, 56500000, 9); 48 | INSERT INTO singers_spotify_performance VALUES 49 | (2, 43700000, 34); 50 | INSERT INTO singers_spotify_performance VALUES 51 | (3, 9650000, 1000); 52 | INSERT INTO singers_spotify_performance VALUES 53 | (4, 73700000, 4); 54 | INSERT INTO singers_spotify_performance VALUES 55 | (5, 16200000, 277); 56 | INSERT INTO singers_spotify_performance VALUES 57 | (6, 39300000, 41); 58 | INSERT INTO singers_spotify_performance VALUES 59 | (7, 33700000, 61); 60 | 61 | --Display data from all tables, sorted by Spotify global rank 62 | SELECT singers_spotify_performance.global_rank AS spotify_rank, famous_singers.name, famous_singers.age, singers_birthplaces.name AS birthplace, singers_spotify_performance.monthly_listeners AS spotify_monthly_listeners FROM famous_singers 63 | JOIN singers_birthplaces 64 | ON singers_birthplaces.id = famous_singers.id 65 | JOIN singers_spotify_performance 66 | ON singers_spotify_performance.id = famous_singers.id 67 | ORDER BY spotify_rank 68 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amy Brown's SQL Portfolio 2 | 3 | Hello, and thanks for stopping by! This repository contains examples of SQL I've written for solo projects and while working through SQL, machine learning, and other data analytics courses. Below are a few highlighted projects, including data visualizations I created using Tableau. Feel free to take a look around and [reach out](https://www.linkedin.com/in/amymartikabrown/) if you have any feedback or questions. 4 | 5 | ## Highlighted Projects 6 | * **Spotify Top Songs Analaysis** - [SQL](https://github.com/amymartika/SQL/blob/main/Spotify%20Top%20Songs%202021%20Data%20Analysis): In this project, I used a dataset found on Kaggle to analyze trends in the top 50 songs of 2021. Using pitch-class integer notation, I examined the key and tonality for these top songs. I joined data from a Hooktheory database to compare the most popular song keys with the song keys most represented in the top 50 Spotify tracks of 2021. 7 | * **Predictive Book Ratings Analysis** - [SQL](https://github.com/amymartika/SQL/blob/main/Predicting%20Book%20Ratings): In this project, I used my own data from Goodreads to analyze how my book ratings differ from the average ratings found on Goodreads. I categorized the books by genre and obtained the average difference in rating per genre. I created another table containing similar data for books that won the Booker Prize for Fiction from 2000-2021 and joined this data to predict, for each Booker Prize-winning book, what my rating would be. 8 | 9 | ### Superstore Profit Dashboard - [Tableau](https://public.tableau.com/app/profile/amymartika/viz/ExecutiveOverview_16733205488000/ExecutiveOverview) 10 | - **Data:** Tableau sample data 11 | - **Audience:** Sales executives 12 | - **Purpose:** Identify factors behind low profit ratio in order to boost profits 13 | 14 | In this dashboard, I used a Tableau dataset containing sample sales data from 2018 to 2021. Though the sample dataset provides a wider overview of sales data, I saw an opportunity to strategically visualize clear, actionable insights to my fictional audience of sales executives. The dashboard allows my audience to immediately pinpoint the geographical, categorical, and seasonal factors that are leading to profit loss — providing the guided insight that allows them to impact change on their team. 15 | 16 | ### World Happiness Rankings Dashboard - [Tableau](https://public.tableau.com/app/profile/amymartika/viz/WorldHappinessReport_16737679931360/WorldHappinessReport) 17 | - **Data:** [World Happiness Report](https://www.kaggle.com/datasets/unsdsn/world-happiness) 18 | - **Audience:** Anyone interested in geography & culture 19 | - **Purpose:** Explore and interact with visualized world happiness data 20 | 21 | The World Happiness Report dataset ranks the happiness of 155 countries from 2015 to 2019. For this dashboard, I wanted the audience to be able to dive deeper into countries around the world and gain a contextual understanding of where those countries rank against the world average. The dashboard allows the user to explore the world map and compare metrics across countries. I'm endlessly interested in world geography and cultural nuances, so I created a dashboard that gets right to the information points I would most want to play with. 22 | 23 | 24 | -------------------------------------------------------------------------------- /Stack Overflow Questions & Answers: -------------------------------------------------------------------------------- 1 | --Dataset: "stackoverflow" from BigQuery 2 | --Source: https://www.kaggle.com/datasets/stackoverflow/stackoverflow 3 | --Queried using: Kaggle Notebook 4 | 5 | from google.cloud import bigquery 6 | 7 | # Create a "Client" object 8 | client = bigquery.Client() 9 | 10 | # Construct a reference to the "stackoverflow" dataset 11 | dataset_ref = client.dataset("stackoverflow", project="bigquery-public-data") 12 | 13 | # API request - fetch the dataset 14 | dataset = client.get_dataset(dataset_ref) 15 | 16 | # Construct a reference to the "posts_questions" table 17 | table_ref = dataset_ref.table("posts_questions") 18 | 19 | # API request - fetch the table 20 | table = client.get_table(table_ref) 21 | 22 | # Preview the first five lines of the table 23 | client.list_rows(table, max_results=5).to_dataframe() 24 | 25 | # Construct a reference to the "posts_answers" table 26 | table_ref = dataset_ref.table("posts_answers") 27 | 28 | # API request - fetch the table 29 | table = client.get_table(table_ref) 30 | 31 | # Preview the first five lines of the table 32 | client.list_rows(table, max_results=5).to_dataframe() 33 | 34 | # How long does it take for questions to receive answers? 35 | correct_query = """ 36 | SELECT q.id AS q_id, 37 | MIN(TIMESTAMP_DIFF(a.creation_date, q.creation_date, SECOND)) as time_to_answer 38 | FROM `bigquery-public-data.stackoverflow.posts_questions` AS q 39 | LEFT JOIN `bigquery-public-data.stackoverflow.posts_answers` AS a 40 | ON q.id = a.parent_id 41 | WHERE q.creation_date >= '2018-01-01' and q.creation_date < '2018-02-01' 42 | GROUP BY q_id 43 | ORDER BY time_to_answer 44 | """ 45 | 46 | # Run the query, and return a pandas DataFrame 47 | correct_result = client.query(correct_query).result().to_dataframe() 48 | print("Percentage of answered questions: %s%%" % \ 49 | (sum(correct_result["time_to_answer"].notnull()) / len(correct_result) * 100)) 50 | print("Number of questions:", len(correct_result)) 51 | 52 | # Which users have only asked questions or provided answers -- but not both? 53 | q_and_a_query = """ 54 | SELECT q.owner_user_id AS owner_user_id, 55 | MIN(q.creation_date) AS q_creation_date, 56 | MIN(a.creation_date) AS a_creation_date 57 | FROM `bigquery-public-data.stackoverflow.posts_questions` AS q 58 | FULL JOIN `bigquery-public-data.stackoverflow.posts_answers` AS a 59 | ON q.owner_user_id = a.owner_user_id 60 | WHERE q.creation_date >= '2019-01-01' AND q.creation_date < '2019-02-01' 61 | AND a.creation_date >= '2019-01-01' AND a.creation_date < '2019-02-01' 62 | GROUP BY owner_user_id 63 | """ 64 | 65 | # Query activity of users who joined the site in January 2019 66 | three_tables_query = """ 67 | SELECT u.id AS id, 68 | MIN(q.creation_date) AS q_creation_date, 69 | MIN(a.creation_date) AS a_creation_date 70 | FROM `bigquery-public-data.stackoverflow.users` AS u 71 | LEFT JOIN `bigquery-public-data.stackoverflow.posts_answers` AS a 72 | ON a.owner_user_id = u.id 73 | LEFT JOIN `bigquery-public-data.stackoverflow.posts_questions` AS q 74 | ON q.owner_user_id = u.id 75 | WHERE u.creation_date >= '2019-01-01' AND u.creation_date < '2019-02-01' 76 | GROUP BY id 77 | """ 78 | 79 | # How many distinct users posted on January 1, 2019? 80 | all_users_query = """ 81 | SELECT q.owner_user_id 82 | FROM `bigquery-public-data.stackoverflow.posts_questions` AS q 83 | WHERE EXTRACT(DATE FROM q.creation_date) = '2019-01-01' 84 | UNION DISTINCT 85 | SELECT a.owner_user_id 86 | FROM `bigquery-public-data.stackoverflow.posts_answers` AS a 87 | WHERE EXTRACT(DATE FROM a.creation_date) = '2019-01-01' 88 | """ 89 | -------------------------------------------------------------------------------- /Digital Media Store Data Analysis: -------------------------------------------------------------------------------- 1 | --Dataset: Digital media store's artists, albums, media tracks, invoices, and customers 2 | --Source: Data Analytics Certificate Course, Break Into Tech 3 | --Queried using: SQLite 3 4 | 5 | --First, answer questions prompted in the course. 6 | --#1. Show full name, customer ID, and country for all customers who are not in the USA 7 | SELECT 8 | firstname, 9 | lastname, 10 | customerid, 11 | country 12 | FROM customers 13 | WHERE country <> 'USA' 14 | ORDER BY country; 15 | 16 | --#2. Show only the customers from Brazil 17 | SELECT 18 | customerid, 19 | firstname, 20 | lastname, 21 | country 22 | FROM customers 23 | WHERE country = 'Brazil'; 24 | 25 | --#3. Find the invoices of customers who are from Brazil and display the customer's full name, invoice ID, date of invoice, and billing country 26 | SELECT 27 | c.firstname, 28 | c.lastname, 29 | i.invoiceid, 30 | i.invoicedate, 31 | i.billingcountry 32 | FROM customers AS c 33 | LEFT JOIN invoices AS i 34 | ON c.customerid = i.customerid 35 | WHERE i.billingcountry = 'Brazil'; 36 | 37 | --#4. Show the employees who are sales agents 38 | SELECT 39 | employeeid, 40 | firstname, 41 | lastname, 42 | title 43 | FROM employees 44 | WHERE title = 'Sales Support Agent' 45 | ORDER BY lastname; 46 | 47 | --#5. Find a unique list of billing countries from the invoices table 48 | SELECT 49 | DISTINCT billingcountry 50 | FROM invoices 51 | ORDER BY billingcountry; 52 | 53 | --#6. Show the invoice IDs associated with each sales agent, including the sales agent's full name 54 | SELECT 55 | e.firstname, 56 | e.lastname, 57 | i.invoiceid 58 | FROM customers AS c 59 | JOIN employees AS e 60 | ON c.supportrepid = e.employeeid 61 | JOIN invoices AS i 62 | ON c.customerid = i.customerid 63 | ORDER BY e.lastname; 64 | 65 | --#7. Show the invoice total, customer name, country, and sales agent for all invoices and customers 66 | SELECT 67 | i.invoiceid, 68 | i.total AS invoice_total, 69 | c.firstname AS customer_first_name, 70 | c.lastname AS customer_last_name, 71 | c.country AS customer_country, 72 | e.firstname AS employee_first_name, 73 | e.lastname AS employee_last_name 74 | FROM customers AS c 75 | FULL JOIN invoices AS i 76 | ON c.customerid = i.customerid 77 | LEFT JOIN employees AS e 78 | ON c.supportrepid = e.employeeid 79 | ORDER BY i.invoiceid; 80 | 81 | --#8. How many invoices were there in 2009? 82 | SELECT 83 | COUNT(invoiceid) AS '2009_sales' 84 | FROM invoices 85 | WHERE invoicedate LIKE '%2009%'; 86 | 87 | --#9. What are the total sales for 2009? 88 | SELECT 89 | ROUND(SUM(total), 2) AS total_sales 90 | FROM invoices 91 | WHERE invoicedate LIKE '%2009%'; 92 | 93 | --#10. Show the purchased track name with each invoice line ID 94 | SELECT 95 | i.invoicelineid, 96 | t.name AS track_name 97 | FROM invoice_items AS i 98 | JOIN tracks AS t 99 | ON i.trackid = t.trackid 100 | ORDER BY i.invoicelineid; 101 | 102 | --#11. Show the purchased track name and artist name with each invoice line ID 103 | SELECT 104 | inv.invoicelineid, 105 | tra.name AS track_name, 106 | art.name AS artist 107 | FROM invoice_items AS inv 108 | LEFT JOIN tracks AS tra 109 | ON inv.trackid = tra.trackid 110 | INNER JOIN albums AS alb 111 | ON tra.albumid = alb.albumid 112 | LEFT JOIN artists AS art 113 | ON alb.artistid = art.artistid 114 | ORDER BY inv.invoicelineid; 115 | 116 | --#12. Show all the tracks and include the album name, media type, and genre 117 | SELECT 118 | t.trackid, 119 | t.name AS track_name, 120 | a.title AS album, 121 | m.name AS media_type, 122 | g.name AS genre 123 | FROM tracks as t 124 | JOIN albums AS a 125 | ON t.albumid = a.albumid 126 | JOIN media_types AS m 127 | ON t.mediatypeid = m.mediatypeid 128 | JOIN genres AS g 129 | ON t.genreid = g.genreid; 130 | 131 | --#13. Show the total sales made by each sales agent 132 | SELECT 133 | e.firstname, 134 | e.lastname, 135 | ROUND(SUM(i.total), 2) AS total_sales 136 | FROM customers AS c 137 | JOIN employees AS e 138 | ON c.supportrepid = e.employeeid 139 | JOIN invoices AS i 140 | ON c.customerid = i.customerid 141 | GROUP BY c.supportrepid 142 | ORDER BY total_sales DESC; 143 | 144 | --#14. Which sales agent made the most dollars in sales in 2009? 145 | SELECT 146 | e.firstname, 147 | e.lastname, 148 | ROUND(SUM(i.total), 2) AS dollars_made 149 | FROM customers AS c 150 | JOIN employees AS e 151 | ON c.supportrepid = e.employeeid 152 | JOIN invoices AS i 153 | ON c.customerid = i.customerid 154 | WHERE i.invoicedate LIKE '%2009%' 155 | GROUP BY c.supportrepid 156 | ORDER BY dollars_made DESC 157 | LIMIT 1; 158 | -------------------------------------------------------------------------------- /Customer & Order Analytics: -------------------------------------------------------------------------------- 1 | --This SQL provides insight into customer and order data. 2 | --Source: Database with 6 tables containing customer data and sales data from January through May. 3 | 4 | --How many orders were placed in January? 5 | SELECT COUNT(orderID) FROM BIT_DB.JanSales 6 | WHERE orderID <> '' 7 | AND orderID <> 'Order ID'; 8 | 9 | --How many of those orders were for an iPhone? 10 | SELECT COUNT(orderID) FROM BIT_DB.JanSales 11 | WHERE Product = 'iPhone' 12 | AND orderID <> '' 13 | AND orderID <> 'Order ID'; 14 | 15 | --Select the customer account numbers for all the orders that were placed in February. 16 | SELECT 17 | DISTINCT customers.acctnum 18 | FROM BIT_DB.customers AS customers 19 | INNER JOIN BIT_DB.FebSales AS feb_sales 20 | ON BIT_DB.customers.order_id = BIT_DB.feb_sales.orderID 21 | WHERE feb_sales.orderID <> '' 22 | AND feb_sales.orderID <> 'Order ID'; 23 | 24 | --Which product was the cheapest one sold in January, and what was the price? 25 | SELECT 26 | DISTINCT Product, 27 | price 28 | FROM BIT_DB.JanSales 29 | ORDER BY price ASC 30 | LIMIT 1; 31 | 32 | --What is the total revenue for each product sold in January? 33 | SELECT 34 | Product, 35 | ROUND(SUM(Quantity * price), 2) AS total_revenue 36 | FROM BIT_DB.JanSales 37 | GROUP BY Product 38 | ORDER BY total_revenue DESC; 39 | 40 | --How many products were sold in February at 548 Lincoln St, Seattle, WA 98101, and what was the total revenue of these products? 41 | SELECT 42 | Quantity, 43 | Product, 44 | SUM(Quantity * price) AS total_revenue 45 | FROM BIT_DB.FebSales 46 | WHERE location = '548 Lincoln St, Seattle, WA 98101' 47 | GROUP BY Product; 48 | 49 | --How many customers ordered more than two products at a time in February, and what was the average amount spent for those customers? 50 | SELECT 51 | COUNT(DISTINCT customers.acctnum) AS customers_buying_min3_products_in_Feb, 52 | ROUND(AVG(Quantity * price), 2) AS average_amount_spent 53 | FROM BIT_DB.customers AS customers 54 | LEFT JOIN BIT_DB.FebSales AS feb_sales 55 | ON customers.order_ID = feb_sales.orderID 56 | WHERE feb_sales.Quantity > 2 57 | AND customers.order_ID <> '' 58 | AND customers.order_ID <> 'Order ID'; 59 | 60 | --List all the products sold in Los Angeles in February, and include how many of each were sold. 61 | SELECT 62 | Product, 63 | SUM(Quantity) AS total_quantity 64 | FROM BIT_DB.FebSales 65 | WHERE location LIKE '%Los Angeles%' 66 | AND Product <> '' 67 | AND Product <> 'Product' 68 | GROUP BY Product 69 | ORDER BY total_quantity DESC; 70 | 71 | --Which locations in New York received at least 3 orders in January, and how many orders did they each receive? 72 | SELECT 73 | DISTINCT location, 74 | COUNT(orderID) AS total_orders 75 | FROM BIT_DB.JanSales 76 | GROUP BY location 77 | HAVING location LIKE '%NY%' 78 | AND total_orders >= 3 79 | ORDER BY location ASC; 80 | 81 | --How many of each type of headphone were sold in February? 82 | SELECT 83 | Product, 84 | SUM(Quantity) AS quantity_sold 85 | FROM BIT_DB.FebSales 86 | GROUP BY Product 87 | HAVING Product LIKE '%Headphones%' 88 | ORDER BY quantity_sold DESC; 89 | 90 | --What was the average amount spent per account in February? (overall average, not average for each account) 91 | SELECT 92 | SUM(Quantity * price) / COUNT(customers.acctnum) AS average_amount_spent 93 | FROM BIT_DB.FebSales AS feb_sales 94 | LEFT JOIN BIT_DB.customers AS customers 95 | ON BIT_DB.feb_sales.orderID = BIT_DB.customers.order_ID 96 | WHERE orderid <> '' 97 | AND orderid <> 'Order ID'; 98 | 99 | --What was the average quantity of products purchased per account in February? (overall average, not average for each account) 100 | SELECT 101 | SUM(Quantity) / COUNT(customers.acctnum) AS average_items_purchased 102 | FROM BIT_DB.FebSales AS feb_sales 103 | LEFT JOIN BIT_DB.customers AS customers 104 | ON BIT_DB.feb_sales.orderID = BIT_DB.customers.order_id 105 | WHERE orderid <> '' 106 | AND orderid <> 'Order ID'; 107 | 108 | --Which product brought in the most revenue in January and how much revenue did it bring in? 109 | SELECT 110 | Product, 111 | ROUND(SUM(Quantity * price), 2) AS total_revenue 112 | FROM BIT_DB.JanSales 113 | GROUP BY Product 114 | HAVING Product <> '' 115 | AND Product <> 'Product' 116 | ORDER BY total_revenue DESC 117 | LIMIT 1; 118 | 119 | --Query the account numbers, count of order IDs, product, quantity, price, order date, and location for all orders that were placed in February. 120 | SELECT 121 | c.acctnum, 122 | count(f.orderID) AS orders, 123 | f.product, 124 | f.quantity, 125 | f.price, 126 | f.orderdate, 127 | f.location 128 | FROM BIT_DB.FebSales AS f 129 | INNER JOIN BIT_DB.customers AS c 130 | ON f.orderid = c.order_id 131 | GROUP BY 132 | c.acctnum, 133 | f.product, 134 | f.quantity, 135 | f.price, 136 | f.orderdate, 137 | f.location; 138 | -------------------------------------------------------------------------------- /Spotify Top Songs 2021 Data Analysis: -------------------------------------------------------------------------------- 1 | /* 2 | Dataset: Spotify Top 50 Songs in 2021 3 | Source: https://www.kaggle.com/datasets/equinxx/spotify-top-50-songs-in-2021 4 | Query Editor: SQLite 3 5 | */ 6 | 7 | /* 8 | Use pitch-class integer notation to assign a primary key to each song. 9 | Pitch-class integer notation source: https://smbutterfield.github.io/ibmt17-18/22-intro-to-non-diatonic-materials/b2-tx-pcintnotation.html 10 | */ 11 | 12 | with notation as ( 13 | select 14 | id, 15 | case 16 | when song_key = 0 and song_mode = 1 then 'C Major' 17 | when song_key = 0 and song_mode = 0 then 'C Minor' 18 | when song_key = 1 and song_mode = 1 then 'C#/Db Major' 19 | when song_key = 1 and song_mode = 0 then 'C#/Db Minor' 20 | when song_key = 2 and song_mode = 1 then 'D Major' 21 | when song_key = 2 and song_mode = 0 then 'D Minor' 22 | when song_key = 3 and song_mode = 1 then 'D#/Eb Major' 23 | when song_key = 3 and song_mode = 0 then 'D#/Eb Minor' 24 | when song_key = 4 and song_mode = 1 then 'E Major' 25 | when song_key = 4 and song_mode = 0 then 'E Minor' 26 | when song_key = 5 and song_mode = 1 then 'F Major' 27 | when song_key = 5 and song_mode = 0 then 'F Minor' 28 | when song_key = 6 and song_mode = 1 then 'F#/Gb Major' 29 | when song_key = 6 and song_mode = 0 then 'F#/Gb Minor' 30 | when song_key = 7 and song_mode = 1 then 'G Major' 31 | when song_key = 7 and song_mode = 0 then 'G Minor' 32 | when song_key = 8 and song_mode = 1 then 'G#/Ab Major' 33 | when song_key = 8 and song_mode = 0 then 'G#/Ab Minor' 34 | when song_key = 9 and song_mode = 1 then 'A Major' 35 | when song_key = 9 and song_mode = 0 then 'A Minor' 36 | when song_key = 10 and song_mode = 1 then 'A#/Bb Major' 37 | when song_key = 10 and song_mode = 0 then 'A#/Bb Minor' 38 | when song_key = 11 and song_mode = 1 then 'B Major' 39 | when song_key = 11 and song_mode = 0 then 'B Minor' 40 | end as key 41 | from bit_db.spotifydata 42 | ) 43 | 44 | select 45 | notation.key, 46 | count(d.id) as total 47 | from bit_db.spotifydata as d 48 | 49 | left join notation 50 | on d.id = notation.id 51 | 52 | group by notation.key 53 | 54 | order by total desc; 55 | 56 | /* 57 | Create a table with the popularity rankings for each song key. 58 | Song keys ranked by popularity source: https://www.hooktheory.com/cheat-sheet/key-popularity 59 | */ 60 | 61 | create table bit_db.popular_song_keys ( 62 | id integer primary key, 63 | song_key varchar not null, 64 | popularity integer not null); 65 | 66 | insert into bit_db.popular_song_keys (song_key, popularity) 67 | values ('C Major', 1); 68 | 69 | insert into bit_db.popular_song_keys (song_key, popularity) 70 | values ('D Major', 2); 71 | 72 | insert into bit_db.popular_song_keys (song_key, popularity) 73 | values ('G Major', 3); 74 | 75 | insert into bit_db.popular_song_keys (song_key, popularity) 76 | values ('A Major', 4); 77 | 78 | insert into bit_db.popular_song_keys (song_key, popularity) 79 | values ('E Major', 5); 80 | 81 | insert into bit_db.popular_song_keys (song_key, popularity) 82 | values ('A Minor', 6); 83 | 84 | insert into bit_db.popular_song_keys (song_key, popularity) 85 | values ('F Major', 7); 86 | 87 | insert into bit_db.popular_song_keys (song_key, popularity) 88 | values ('C Minor', 8); 89 | 90 | insert into bit_db.popular_song_keys (song_key, popularity) 91 | values ('E Minor', 9); 92 | 93 | insert into bit_db.popular_song_keys (song_key, popularity) 94 | values ('D Minor', 10); 95 | 96 | insert into bit_db.popular_song_keys (song_key, popularity) 97 | values ('D#/Eb Major', 11); 98 | 99 | insert into bit_db.popular_song_keys (song_key, popularity) 100 | values ('G Minor', 12); 101 | 102 | insert into bit_db.popular_song_keys (song_key, popularity) 103 | values ('A#/Bb Major', 13); 104 | 105 | insert into bit_db.popular_song_keys (song_key, popularity) 106 | values ('B Minor', 14); 107 | 108 | insert into bit_db.popular_song_keys (song_key, popularity) 109 | values ('F#/Gb Minor', 15); 110 | 111 | insert into bit_db.popular_song_keys (song_key, popularity) 112 | values ('F Minor', 16); 113 | 114 | insert into bit_db.popular_song_keys (song_key, popularity) 115 | values ('C#/Db Major', 17); 116 | 117 | insert into bit_db.popular_song_keys (song_key, popularity) 118 | values ('F#/Gb Major', 18); 119 | 120 | insert into bit_db.popular_song_keys (song_key, popularity) 121 | values ('B Major', 19); 122 | 123 | insert into bit_db.popular_song_keys (song_key, popularity) 124 | values ('C#/Db Minor', 20); 125 | 126 | insert into bit_db.popular_song_keys (song_key, popularity) 127 | values ('D#/Eb Minor', 21); 128 | 129 | insert into bit_db.popular_song_keys (song_key, popularity) 130 | values ('G#/Ab Major', 22); 131 | 132 | insert into bit_db.popular_song_keys (song_key, popularity) 133 | values ('A#/Bb Minor', 23); 134 | 135 | insert into bit_db.popular_song_keys (song_key, popularity) 136 | values ('G#/Ab Minor', 24); 137 | -------------------------------------------------------------------------------- /City Bike Lane Data: -------------------------------------------------------------------------------- 1 | --Dataset: City bike lane data 2 | --Source: Data Analytics Certificate Course, Break Into Tech 3 | --Queried using: SQLite 3 4 | 5 | --Create table for city bike lanes data 6 | CREATE TABLE BIT_DB.CityBikeLanes ( 7 | id integer primary key, 8 | year_installed year not null, 9 | year_updated year not null, 10 | street varchar not null, 11 | width_feet integer not null, 12 | safetyrating integer not null, 13 | protected varchar not null); 14 | 15 | INSERT INTO BIT_DB.CityBikeLanes values(1,2012, 2020, "Chestnut",4,4,"yes"); 16 | INSERT INTO BIT_DB.CityBikeLanes values(2,2016, 2020,"Walnut",4,3.8,"yes"); 17 | INSERT INTO BIT_DB.CityBikeLanes values(3,2011, 2020, "Market", 3.5, 2, "no"); 18 | INSERT INTO BIT_DB.CityBikeLanes values(4,2008, 2020,"Locust",4,5,"yes"); 19 | INSERT INTO BIT_DB.CityBikeLanes values(5,2002, 2020,"South",4.5,4.3,"no"); 20 | INSERT INTO BIT_DB.CityBikeLanes values(6,2012, 2021, "18th",4,4.7,"yes"); 21 | INSERT INTO BIT_DB.CityBikeLanes values(7,2016, 2021,"2nd",4,3.7,"yes"); 22 | INSERT INTO BIT_DB.CityBikeLanes values(8,2011, 2021, "Lombard", 3.5, 2.2, "no"); 23 | INSERT INTO BIT_DB.CityBikeLanes values(9,2008, 2021,"Pine",4,4.9,"yes"); 24 | INSERT INTO BIT_DB.CityBikeLanes values(10,2002, 2021,"Tasker",4.5,4.8,"no"); 25 | INSERT INTO BIT_DB.CityBikeLanes values(11,2012, 2020, "Earp",4,4.1,"yes"); 26 | INSERT INTO BIT_DB.CityBikeLanes values(12,2016, 2020,"Titan",4,3.8,"yes"); 27 | INSERT INTO BIT_DB.CityBikeLanes values(13,2011, 2020, "Manning", 3.4, 2, "no"); 28 | INSERT INTO BIT_DB.CityBikeLanes values(14,2008, 2020,"Fieldcrest",4,4.9,"yes"); 29 | INSERT INTO BIT_DB.CityBikeLanes values(15,2002, 2020,"York",4.5,4.5,"no"); 30 | INSERT INTO BIT_DB.CityBikeLanes values(16,2012, 2021, "Race",4,4.7,"yes"); 31 | INSERT INTO BIT_DB.CityBikeLanes values(17,2016, 2021,"Museum",4,3.8,"yes"); 32 | INSERT INTO BIT_DB.CityBikeLanes values(18,2011, 2021, "Altin", 3.5, 2, "no"); 33 | INSERT INTO BIT_DB.CityBikeLanes values(19,2008, 2021,"Fred",4,4.5,"yes"); 34 | INSERT INTO BIT_DB.CityBikeLanes values(20,2002, 2021,"Morris",4.5,4.7,"no"); 35 | INSERT INTO BIT_DB.CityBikeLanes values(21,2012, 2020, "Jameson",4,3.9,"yes"); 36 | INSERT INTO BIT_DB.CityBikeLanes values(22,2016, 2020,"MLK",4,3.9,"yes"); 37 | INSERT INTO BIT_DB.CityBikeLanes values(23,2011, 2020, "Parker", 3.6, 2, "no"); 38 | INSERT INTO BIT_DB.CityBikeLanes values(24,2008, 2020,"Thomas",4,4.8,"yes"); 39 | INSERT INTO BIT_DB.CityBikeLanes values(25,2002, 2020,"Running",4.5,4.3,"no"); 40 | INSERT INTO BIT_DB.CityBikeLanes values(26,2012, 2021, "Waverly",4,4.5,"yes"); 41 | INSERT INTO BIT_DB.CityBikeLanes values(27,2016, 2021,"Addison",4,3.9,"yes"); 42 | INSERT INTO BIT_DB.CityBikeLanes values(28,2011, 2021, "Beaver", 3.5, 2.1, "no"); 43 | INSERT INTO BIT_DB.CityBikeLanes values(29,2008, 2021,"Kensington",4,5,"yes"); 44 | INSERT INTO BIT_DB.CityBikeLanes values(30,2002, 2021,"Mouse",4.5,4.5,"no"); 45 | INSERT INTO BIT_DB.CityBikeLanes values(31,2012, 2020, "Chestnut",4,4.5,"yes"); 46 | INSERT INTO BIT_DB.CityBikeLanes values(32,2016, 2020,"Walnut",4,3.7,"yes"); 47 | INSERT INTO BIT_DB.CityBikeLanes values(33,2011, 2020, "Market", 3.8, 2, "no"); 48 | INSERT INTO BIT_DB.CityBikeLanes values(34,2008, 2020,"Locust",4,4.8,"yes"); 49 | INSERT INTO BIT_DB.CityBikeLanes values(35,2002, 2020,"South",4.5,4.7,"no"); 50 | INSERT INTO BIT_DB.CityBikeLanes values(36,2012, 2021, "18th",4,4.7,"yes"); 51 | INSERT INTO BIT_DB.CityBikeLanes values(37,2016, 2021,"2nd",4,3.2,"yes"); 52 | INSERT INTO BIT_DB.CityBikeLanes values(38,2011, 2021, "Lombard", 3.5, 2.5, "no"); 53 | INSERT INTO BIT_DB.CityBikeLanes values(39,2008, 2021,"Pine",4,5,"yes"); 54 | INSERT INTO BIT_DB.CityBikeLanes values(40,2002, 2021,"Tasker",4.5,4.3,"no"); 55 | INSERT INTO BIT_DB.CityBikeLanes values(41,2012, 2020, "Earp",4,4.5,"yes"); 56 | INSERT INTO BIT_DB.CityBikeLanes values(42,2016, 2020,"Titan",4,3.9,"yes"); 57 | INSERT INTO BIT_DB.CityBikeLanes values(43,2011, 2020, "Manning", 3.4, 2.7, "no"); 58 | INSERT INTO BIT_DB.CityBikeLanes values(44,2008, 2020,"Fieldcrest",4,4.7,"yes"); 59 | INSERT INTO BIT_DB.CityBikeLanes values(45,2002, 2020,"York",4.5,4.4,"no"); 60 | INSERT INTO BIT_DB.CityBikeLanes values(46,2012, 2021, "Race",4,4.9,"yes"); 61 | INSERT INTO BIT_DB.CityBikeLanes values(47,2016, 2021,"Museum",4,3.4,"yes"); 62 | INSERT INTO BIT_DB.CityBikeLanes values(48,2011, 2021, "Altin", 3.7, 2, "no"); 63 | INSERT INTO BIT_DB.CityBikeLanes values(49,2008, 2021,"Fred",4,4.7,"yes"); 64 | INSERT INTO BIT_DB.CityBikeLanes values(50,2002, 2021,"Morris",4.5,4.4,"no"); 65 | INSERT INTO BIT_DB.CityBikeLanes values(51,2012, 2020, "Jameson",4,4,"yes"); 66 | INSERT INTO BIT_DB.CityBikeLanes values(52,2016, 2020,"MLK",4,4,"yes"); 67 | INSERT INTO BIT_DB.CityBikeLanes values(53,2011, 2020, "Parker", 3.6, 2.3, "no"); 68 | INSERT INTO BIT_DB.CityBikeLanes values(54,2008, 2020,"Thomas",4,4.5,"yes"); 69 | INSERT INTO BIT_DB.CityBikeLanes values(55,2002, 2020,"Running",4.5,4.5,"no"); 70 | INSERT INTO BIT_DB.CityBikeLanes values(56,2012, 2021, "Waverly",4,4.7,"yes"); 71 | INSERT INTO BIT_DB.CityBikeLanes values(57,2016, 2021,"Addison",4,3.6,"yes"); 72 | INSERT INTO BIT_DB.CityBikeLanes values(58,2011, 2021, "Beaver", 3.5, 2.5, "no"); 73 | INSERT INTO BIT_DB.CityBikeLanes values(59,2008, 2021,"Kensington",4,4.9,"yes"); 74 | INSERT INTO BIT_DB.CityBikeLanes values(60,2002, 2021,"Mouse",4.5,4.3,"no"); 75 | 76 | -- Get an overview of the data 77 | SELECT * FROM CityBikeLanes LIMIT 10; 78 | 79 | SELECT * FROM CityBikeLanes WHERE street='Walnut'; 80 | 81 | --Provide a list of all the bike lanes that have an average safety rating of 4.0 or higher, their respective safety rating, and a label that says "Safe Lane." 82 | WITH average_safety_CTE AS ( 83 | SELECT 84 | bike_lanes.street, 85 | AVG(safetyrating) AS average_safety 86 | FROM CityBikeLanes AS bike_lanes 87 | GROUP BY bike_lanes.street 88 | ) 89 | 90 | SELECT 91 | street, 92 | average_safety, 93 | 'Safe Lane' AS tag 94 | FROM average_safety_CTE 95 | WHERE average_safety >= 4 96 | ORDER BY average_safety DESC; 97 | 98 | SELECT street, safetyrating, 99 | AVG(safetyrating) OVER (PARTITION BY street) as "Average_safety_rating" 100 | FROM CityBikeLanes; 101 | 102 | --Provide a list of all the bike lanes, both safety ratings for each lane, the average safety rating for each lane, and a label with the recommendation as "Remove" (avg. safety rating less than 2.5), "Leave As-Is" (avg. safety rating of 4 or more), or "Improvements Needed" (all other streets). 103 | SELECT 104 | street, 105 | safetyrating, 106 | AVG(safetyrating) OVER (PARTITION BY street) AS average_safety_rating, 107 | CASE 108 | WHEN AVG(safetyrating) OVER (PARTITION BY safetyrating) >= 4 THEN 'Leave As-Is' 109 | WHEN AVG(safetyrating) OVER (PARTITION BY safetyrating) < 2.5 THEN 'Remove' 110 | ELSE 'Improvements Needed' 111 | END AS recommendation 112 | FROM CityBikelanes 113 | ORDER BY recommendation; 114 | -------------------------------------------------------------------------------- /Predicting Book Ratings: -------------------------------------------------------------------------------- 1 | --Create table containing books I've rated on Goodreads 2 | CREATE TABLE books_read ( 3 | id INTEGER PRIMARY KEY, 4 | title TEXT, 5 | author TEXT, 6 | genre TEXT, 7 | year_read INTEGER, 8 | my_rating INTEGER, 9 | goodreads_rating INTEGER); 10 | 11 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Queenie", "Candice Carty-Williams", "New adult fiction", 2022, 3, 3.88); 12 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Mrs. Palfrey at the Claremont", "Elizabeth Taylor", "Literary fiction", 2022, 4, 4); 13 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Tales from the Cafe", "Toshikazu Kawaguchi", "Magical realism", 2022, 3, 3.99); 14 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Woman of the Ashes", "Mia Cuoto", "Historical fiction", 2022, 2, 3.84); 15 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("If Beale Street Could Talk", "James Baldwin", "Fiction", 2022, 4, 4.27); 16 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Writers at Work Around the World", "The Paris Review", "Nonfiction", 2022, 4, 4.5); 17 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Convenience Store Woman", "Sayaka Murata", "Fiction", 2022, 3, 3.72); 18 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Things Fall Apart", "Chinua Achebe", "Historical fiction", 2022, 4, 3.71); 19 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Before the Coffee Gets Cold", "Toshikazu Kawaguchi", "Magical realism", 2021, 4, 3.75); 20 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("Dear America: Notes of an Undocumented Citizen", "Jose Antonio Vargas", "Nonfiction", 2021, 4.31); 21 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("Little Weirds", "Jenny Slate", "Autobiography", 2021, 3.85); 22 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Brave New World", "Aldous Huxley", "Dystopian Fiction", 2021, 4, 3.99); 23 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Sincerely,", "F.S. Yousaf", "Poetry", 2021, 3, 3.86); 24 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Handmaid's Tale", "Margaret Atwood", "Dystopian fiction", 2021, 3, 4.12); 25 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Nickel and Dimed: On (Not) Getting by in America", "Barbara Ehrenreich", "Nonfiction", 2021, 2, 3.64); 26 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Bell Jar", "Sylvia Plath", "Autobiographical novel", 2021, 4, 4.03); 27 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("After the Winter", "Guadalupe Nettel", "Literary fiction", 2021, 3, 3.75); 28 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("At Dusk", "Hwang Sok-yong", "Psychological fiction", 2021, 3, 3.69); 29 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("A Little Life", "Hanya Yanagihara", "Fiction", 2021, 2, 4.33); 30 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("The Glass Castle", "Jeannette Walls", "Autobiography", 2021, 4.29); 31 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Catcher in the Rye", "J.D. Salinger", "Fiction", 2021, 4, 3.81); 32 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Ask Again, Yes", "Mary Beath Keane", "Fiction", 2020, 4, 3.95); 33 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Frankenstein", "Mary Shelley", "Science fiction", 2020, 4, 3.84); 34 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Lolita", "Vladimir Nabokov", "Fiction", 2020, 3, 3.88); 35 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potter and the Deathly Hallows", "J.K. Rowling", "Children's literature", 2020, 4, 4.62); 36 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Gone Girl", "Gillian Flynn", "Thriller", 2020, 3, 4.11); 37 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Sky Isn't Visible from Here", "Felicia Sullivan", "Autobiography", 2020, 2, 3.74); 38 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Little Women", "Louisa May Alcott", "Children's literature", 2020, 4, 4.12); 39 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Holes", "Louis Sachar", "Children's literature", 2020, 4, 3.98); 40 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("The Case for Reparations", "Ta-Nehisi Coates", "Nonfiction", 2020, 4.64); 41 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potter and the Half-Blood Prince", "J.K. Rowling", "Children's literature", 2020, 3, 4.57); 42 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("After the Quake", "Haruki Murakami", "Fiction", 2020, 3, 3.78); 43 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Flowers for Algernon", "Daniel Keyes", "Science fiction", 2020, 4, 4.17); 44 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Who's Afraid of Virginia Woolf?", "Edward Albee", "Play", 2020, 4, 4.06); 45 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Hunger Makes Me a Modern Girl", "Carrie Brownstein", "Autobiography", 2020, 3, 3.82); 46 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potter and the Order of the Phoenix", "J.K. Rowling", "Children's literature", 2020, 3, 4.5); 47 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Three Musketeers", "Alexandre Dumas", "Historical Fiction", 2020, 3, 4.08); 48 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Writers at Work: Volume 3", "The Paris Review", "Nonfiction", 2020, 2, 4.25); 49 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Revival", "Stephen King", "Thriller", 2020, 3, 3.79); 50 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potter and the Goblet of Fire", "J.K. Rowling", "Children's literature", 2020, 3, 4.57); 51 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Skipping Christmas", "John Grisham", "Humor", 2019, 3, 3.52); 52 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Little House", "Virginia Lee Burton", "Children's literature", 2019, 3, 4.28); 53 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potter and the Prisoner of Azkaban", "J.K. Rowling", "Children's literature", 2019, 4, 4.58); 54 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Talking as Fast as I Can: From Gilmore Girls to Gilmore Girls", "Lauren Graham", "Autobiography", 2019, 3, 3.95); 55 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potter and the Chamber of Secrets", "J.K. Rowling", "Children's literature", 2019, 3, 4.43); 56 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Metamorphosis", "Franz Kafka", "Fantasy Fiction", 2019, 3, 3.84); 57 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Harry Potters and the Sorcerer's Stone", "J.K. Rowling", "Children's literature", 2019, 4, 4.48); 58 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Naturally Tan", "Tan France", "Autobiography", 2019, 4, 3.81); 59 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Time Machine", "H.G. Wells", "Science fiction", 2019, 3, 3.9); 60 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("My Vanishing African Dreams", "Susan Hall", "Autobiography", 2019, 4.4); 61 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("As Good As True", "Cheryl Reid", "Historical fiction", 2019, 2, 3.75); 62 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("A Farewell to Arms", "Ernest Hemingway", "Fiction", 2019, 3, 3.81); 63 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("The Enneagram Made Easy: Discover the 9 Types of People", "Renee Baron", "Nonfiction", 2019, 3.84); 64 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Fahrenheit 451", "Ray Bradbury", "Science fiction", 2019, 3, 3.98); 65 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("And Then There Were None", "Agatha Christie", "Mystery", 2019, 4, 4.27); 66 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("And the Mountains Echoed", "Khaled Hosseini", "Historical fiction", 2019, 4, 4.06); 67 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("One More Thing: Stories and Other Stories", "B.J. Novak", "Fiction", 2019, 2, 3.67); 68 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Adventures of Huckleberry Finn", "Mark Twain", "Fiction", 2019, 3, 3.82); 69 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("On Writing: A Memoir of the Craft", "Stephen King", "Nonfiction", 2019, 4, 4.33); 70 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("I'm Not Here to Give a Speech", "Gabriel Garcia Marquez", "Biography", 2019, 3, 3.98); 71 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("1984", "George Orwell", "Dystopian fiction", 2019, 4, 4.19); 72 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Educated", "Tara Westover", "Autobiography", 2019, 4, 4.47); 73 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Chronicle of a Death Foretold", "Gabriel Garcia Marquez", "Fiction", 2019, 4, 3.97); 74 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Wild Robot", "Peter Brown", "Children's literatuer", 2019, 4, 4.04); 75 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Through the Looking-Glass and What Alice Found There", "Lewis Carroll", "Children's literature", 2019, 3, 4.04); 76 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Beekeeper's Apprentice", "Laurie R. King", "Mystery", 2019, 2, 4.05); 77 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Bossypants", "Tina Fey", "Autobiography", 2019, 3, 3.95); 78 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("The Essential Enneagram", "David N. Daniels", "Nonfiction", 2019, 3.68); 79 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("State of Fear", "Michael Crichton", "Thriller", 2019, 3, 3.7); 80 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("A Thousand Splendid Suns", "Khaled Hoseini", "Fiction", 2019, 4, 4.4); 81 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Lord of the Flies", "William Golding", "Fiction", 2019, 3, 3.69); 82 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Heidi", "Johanna Spyri", "Children's literature", 2019, 4, 4.01); 83 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Call of the Wild", "Jack London", "Adventure fiction", 2019, 3, 3.89); 84 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Zahir", "Paulo Coelho", "Psychological fiction", 2019, 1, 3.58); 85 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Help", "Kathryn Sockett", "Historical fiction", 2019, 3, 4.46); 86 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Quiet: The Power of Introverts in a World That Can't Stop Talking", "Susan Cain", "Nonfiction", 2019, 4, 4.07); 87 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Tulip Fever", "Deborah Moggach", "Historical fiction", 2019, 3, 3.52); 88 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Bon Voyage Mr. President and Other Stories", "Gabriel Garcia Marquez", "Fiction", 2019, 3, 3.63); 89 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("To Have and Have Not", "Ernest Hemingway", "Fiction", 2019, 3, 3.54); 90 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Prey", "Michael Crichton", "Science fiction", 2019, 2, 3.77); 91 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Hiroshima", "John Hersey", "Nonfiction", 2019, 4, 4); 92 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Goldfinch", "Donna Tartt", "Literary fiction", 2019, 3, 3.93); 93 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Till We Have Faces", "C.S. Lewis", "Fantasy fiction", 2019, 4, 4.16); 94 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Actor's Life: A Survival Guide", "Jenna Fischer", "Nonfiction", 2019, 3, 4.15); 95 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("News of a Kidnapping", "Gabriel Garcia Marquez", "Nonfiction", 2019, 3, 3.87); 96 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Writers at Work: Volume 6", "The Paris Review", "Nonfiction", 2018, 4, 4.25); 97 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Tender Is the Night", "F. Scott Fitzgerald", "Fiction", 2018, 2, 3.8); 98 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("My Antonia", "Willa Cather", "Historical fiction", 2018, 4, 3.81); 99 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Of Norwegian Ways", "Bent Vanberg", "Nonfiction", 2018, 2, 3.28); 100 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Modern Romance", "Aziz Ansari", "Nonfiction", 2018, 4, 3.81); 101 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Writers at Work: Volume 8", "The Paris Review", "Nonfiction", 2018, 4, 4.14); 102 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Ender's Game", "Orson Scott Card", "Science fiction", 2018, 4, 4.3); 103 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Zahir", "Paulo Coelho", "Psychological fiction", 2019, 1, 3.58); 104 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Yes Please", "Amy Poehler", "Autobiography", 2018, 4, 3.84); 105 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Is Everyone Hanging Out Without Me?", "Mindy Kaling", "Autobiography", 2018, 4, 3.86); 106 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Nice Girls Don't Get the Corner Office", "Lois P. Frankel", "Nonfiction", 2018, 3, 3.69); 107 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Beast Within", "Serena Valentino", "Fiction", 2018, 1, 3.77); 108 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Things They Carried", "Tim O'Brien", "Historical fiction", 2018, 3, 4.13); 109 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Boy's Life", "Robert McCammon", "Mystery", 2018, 5, 4.37); 110 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Girl on the Train", "Paula Hawkins", "Thriller", 2018, 3, 3.95); 111 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Kite Runner", "Khaled Hosseini", "Historical fiction", 2018, 4, 4.32); 112 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("To Kill a Mockingbird", "Harper Lee", "Fiction", 2018, 4, 4.27); 113 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Mockingjay", "Suzanne Collins", "Young adult fiction", 2018, 3, 4.06); 114 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Ultimate Law Firm Associate's Marketing Checklist", "Ross Fishman", "Nonfiction", 2018, 3, 4); 115 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Catching Fire", "Suzanne Collins", "Young adult fiction", 2018, 4, 4.3); 116 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Hunger Games", "Suzanne Collins", "Young adult fiction", 2018, 4, 4.32); 117 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Horizon", "Scott Westerfeld", "Adventure fiction", 2018, 3, 3.76); 118 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Bassoon King", "Rainn Wilson", "Autobiography", 2018, 4, 3.72); 119 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Anne of Green Gables", "L.M. Montgomery", "Children's literature", 2018, 4, 4.28); 120 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Why Not Me?", "Mindy Kaling", "Autobiograhpy", 2018, 3, 3.9); 121 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("One Hundred Years of Solitude", "Gabriel Garcia Marquez", "Magical realism", 2017, 5, 4.1); 122 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Sea Wolf", "Jack London", "Adventure fiction", 2017, 4, 4.04); 123 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("The Ruins of Us", "Keija Parssinen", "Literary fiction", 2017, 3, 3.64); 124 | INSERT INTO books_read (title, author, genre, year_read, my_rating, goodreads_rating) VALUES ("Flight Behavior", "Barbara Kingsolver", "Literary fiction", 2017, 2, 3.79); 125 | 126 | --Display all books I've rated through Goodreads from highest to lowest rating 127 | SELECT title, author, my_rating, goodreads_rating 128 | FROM books_read 129 | ORDER BY my_rating DESC; 130 | 131 | --Display which authors I've read more than once, sorted from most to least works read 132 | SELECT author, COUNT(*) AS total_by_author 133 | FROM books_read 134 | GROUP BY author 135 | HAVING total_by_author > 1 136 | ORDER BY total_by_author DESC; 137 | 138 | --Which books did I rate higher than the Goodreads average rating? 139 | SELECT title, author, my_rating, goodreads_rating 140 | FROM books_read 141 | WHERE my_rating > goodreads_rating 142 | ORDER BY my_rating DESC; 143 | 144 | --Which books did I rate lower than the Goodreads average rating? 145 | SELECT title, author, goodreads_rating, my_rating 146 | FROM books_read 147 | WHERE my_rating < goodreads_rating 148 | ORDER BY goodreads_rating DESC; 149 | 150 | --Update table with a new rating for Lolita 151 | SELECT id, title, my_rating FROM books_read WHERE title = "Lolita"; 152 | 153 | UPDATE books_read SET my_rating = 4 WHERE id = 24; 154 | 155 | SELECT id, title, my_rating FROM books_read WHERE id = 24; 156 | 157 | --Update table with a new book read 158 | INSERT INTO books_read (title, author, genre, year_read, goodreads_rating) VALUES ("Verge", "Lidia Yuknavitch", "Literary fiction", 2022, 3.67); 159 | 160 | SELECT id, title, author, goodreads_rating FROM books_read WHERE title = "Verge"; 161 | 162 | --Practice deleting data from the table 163 | SELECT id, title, author FROM books_read WHERE id > 100; 164 | 165 | DELETE FROM books_read WHERE id = 115; 166 | 167 | SELECT id, title, author FROM books_read WHERE id > 100; 168 | 169 | --Display table data sorted by genre 170 | SELECT genre, COUNT(*) as by_genre FROM books_read 171 | GROUP BY genre 172 | ORDER BY by_genre DESC; 173 | 174 | --Update table with corrected typos and title case vs. sentence case 175 | SELECT id, title, genre FROM books_read WHERE genre = "Children's literatuer"; 176 | 177 | UPDATE books_read SET genre = "Children's literature" WHERE id = 64; 178 | 179 | SELECT id, title, genre FROM books_read WHERE id = 64; 180 | 181 | SELECT id, title, genre FROM books_read WHERE genre = "Historical Fiction"; 182 | 183 | UPDATE books_read SET genre = "Historical fiction" WHERE id = 37; 184 | 185 | SELECT id, title, genre FROM books_read WHERE id = 37; 186 | 187 | SELECT id, title, genre FROM books_read WHERE genre = "Fantasy Fiction"; 188 | 189 | UPDATE books_read SET genre = "Fantasy fiction" WHERE id = 46; 190 | 191 | SELECT id, title, genre FROM books_read WHERE id = 46; 192 | 193 | UPDATE books_read SET genre = "Psychological fiction" WHERE id = 1; 194 | 195 | SELECT id, title, genre FROM books_read WHERE id = 1; 196 | 197 | --Display table data sorted by genre with updates 198 | SELECT genre, COUNT(*) as by_genre FROM books_read 199 | GROUP BY genre 200 | ORDER BY by_genre DESC; 201 | 202 | --What is my average rating for each genre? 203 | SELECT genre, AVG(my_rating) as average_rating, COUNT(*) as by_genre FROM books_read 204 | GROUP BY genre 205 | ORDER BY average_rating DESC; 206 | 207 | --Create table containing Booker Prize winners published after 2016 208 | CREATE TABLE booker_prize_winners ( 209 | id INTEGER PRIMARY KEY, 210 | title TEXT, 211 | author TEXT, 212 | year_won INTEGER, 213 | genre TEXT, 214 | goodreads_rating INTEGER); 215 | 216 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Promise", "Damon Galgut", 2021, "Literary fiction", 3.98); 217 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Shuggie Bain", "Douglas Stuart", 2020, "Literary fiction", 4.33); 218 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Testaments", "Margaret Atwood", 2019, "Dystopian fiction", 4.20); 219 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Girl, Woman, Other", "Bernadine Evaristo", 2019, "Literary fiction", 4.34); 220 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Milkman", "Anna Burns", 2018, "Psychological fiction", 3.54); 221 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Lincoln in the Bardo", "George Saunders", 2017, "Historical fiction", 3.75); 222 | 223 | --What is the average difference between my ratings and Goodreads' average ratings for each genre read? 224 | SELECT genre, ROUND(goodreads_rating - my_rating, 2) AS rating_difference FROM books_read 225 | GROUP BY genre 226 | ORDER BY rating_difference DESC; 227 | 228 | --Update Booker Prize table with books published between 2000 and 2016 229 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Sellout", "Paul Beatty", 2016, "Literary fiction", 3.75); 230 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("A Brief History of Seven Killings", "Marlon James", 2015, "Historical fiction", 3.89); 231 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Narrow Road to the Deep North", "Richard Flanagan", 2014, "Historical fiction", 4.02); 232 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Luminaries", "Eleanor Catton", 2013, "Historical fiction", 3.73); 233 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Bring Up the Bodies", "Hilary Mantel", 2012, "Historical fiction", 4.25); 234 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Sense of an Ending", "Julian Barnes", 2011, "Psycholigcal fiction", 3.73); 235 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Elected Member", "Bernice Rubens", 2010, "Literary fiction", 3.65); 236 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Finkler Question", "Howard Jacobson", 2010, "Fiction", 2.8); 237 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Wolf Hall", "Hilary Mantel", 2009, "Historical fiction", 3.89); 238 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The White Tiger", "Aravind Adiga", 2008, "Mystery", 3.76); 239 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Gathering", "Anne Enright", 2007, "Literary fiction", 3.1); 240 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Inheritance of Loss", "Kiran Desai", 2006, "Psychological fiction", 3.44); 241 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Sea", "John Banville", 2005, "Psychological fiction", 3.53); 242 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Line of Beauty", "Alan Hollinghurst", 2004, "Historical fiction", 3.73); 243 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Vernon God Little", "DBC Pierre", 2003, "Fiction", 3.59); 244 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("Life of Pi", "Yann Martel", 2002, "Adventure fiction", 3.93); 245 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("True History of the Kelly Gang", "Peter Carey", 2001, "Historical fiction", 3.83); 246 | INSERT INTO booker_prize_winners (title, author, year_won, genre, goodreads_rating) VALUES ("The Blind Assassin", "Margaret Atwood", 2000, "Psychological fiction", 3.96); 247 | 248 | --Create table predicting my ratings per genre based on the difference between my ratings and Goodreads' average ratings 249 | CREATE TABLE predicting_ratings ( 250 | id INTEGER PRIMARY KEY, 251 | genre TEXT, 252 | average_rating_difference INTEGER); 253 | 254 | SELECT genre, ROUND(my_rating - goodreads_rating, 2) AS average_rating_difference FROM books_read 255 | GROUP BY genre 256 | ORDER BY average_rating_difference DESC; 257 | 258 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Magical realism", 0.9); 259 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Mystery", 0.63); 260 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Autobiography", 0.28); 261 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Autobiographical novel", -0.03); 262 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Adventure fiction", -0.04); 263 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Play", -0.06); 264 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Fantasy fiction", -0.16); 265 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Dystopian fiction", -0.19); 266 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Fiction", -0.27); 267 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Children's literature", -0.28); 268 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Science fiction", -0.3); 269 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Historical fiction", -0.32); 270 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Young adult fiction", -0.32); 271 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Humor", -0.52); 272 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Poetry", -0.86); 273 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Autobiography", -0.9); 274 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Thriller", -0.95); 275 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Biography", -0.98); 276 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Nonfiction", -1); 277 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Literary fiction", -1.79); 278 | INSERT INTO predicting_ratings (genre, average_rating_difference) VALUES ("Psychological fiction", -2.58); 279 | 280 | --Based on predicting_ratings data, what is my predicted rating for Booker Prize winners published after 1999? 281 | SELECT booker_prize_winners.title, booker_prize_winners.author, booker_prize_winners.genre, ROUND(booker_prize_winners.goodreads_rating + predicting_ratings.average_rating_difference,2) AS amys_predicted_rating FROM booker_prize_winners 282 | JOIN predicting_ratings 283 | ON booker_prize_winners.genre = predicting_ratings.genre 284 | ORDER BY amys_predicted_rating DESC; 285 | -------------------------------------------------------------------------------- /Country Populations Database & Stats: -------------------------------------------------------------------------------- 1 | --Create country database 2 | CREATE TABLE countries( 3 | name TEXT PRIMARY KEY, 4 | population INTEGER, 5 | percent_one_year_change REAL, 6 | population_change INTEGER, 7 | density_per_sq_km INTEGER, 8 | area_sq_km INTEGER, 9 | net_migrants INTEGER, 10 | fertility_rate REAL, 11 | median_age REAL, 12 | percent_of_world_pop REAL 13 | ); 14 | 15 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('China',1439323776,0.39,5540090,153,9388211,-348399,1.70,38.00,18.47); 16 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('India',1380004385,0.99,13586631,464,2973190,-532687,2.20,28.00,17.7); 17 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('United States',331002651,0.59,1937734,36,9147420,954806,1.80,38.00,4.25); 18 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Indonesia',273523615,1.07,2898047,151,1811570,-98955,2.30,30.00,3.51); 19 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Pakistan',220892340,2.00,4327022,287,770880,-233379,3.60,23.00,2.83); 20 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Brazil',212559417,0.72,1509890,25,8358140,21200,1.70,33.00,2.73); 21 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Nigeria',206139589,2.58,5175990,226,910770,-60000,5.40,18.00,2.64); 22 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bangladesh',164689383,1.01,1643222,1265,130170,-369501,2.10,28.00,2.11); 23 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Russia',145934462,0.04,62206,9,16376870,182456,1.80,40.00,1.87); 24 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mexico',128932753,1.06,1357224,66,1943950,-60000,2.10,29.00,1.65); 25 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Japan',126476461,-0.30,-383840,347,364555,71560,1.40,48.00,1.62); 26 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Ethiopia',114963588,2.57,2884858,115,1000000,30000,4.30,19.00,1.47); 27 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Philippines',109581078,1.35,1464463,368,298170,-67152,2.60,26.00,1.41); 28 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Egypt',102334404,1.94,1946331,103,995450,-38033,3.30,25.00,1.31); 29 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Vietnam',97338579,0.91,876473,314,310070,-80000,2.10,32.00,1.25); 30 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('DR Congo',89561403,3.19,2770836,40,2267050,23861,6.00,17.00,1.15); 31 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Turkey',84339067,1.09,909452,110,769630,283922,2.10,32.00,1.08); 32 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Iran',83992949,1.30,1079043,52,1628550,-55000,2.20,32.00,1.08); 33 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Germany',83783942,0.32,266897,240,348560,543822,1.60,46.00,1.07); 34 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Thailand',69799978,0.25,174396,137,510890,19444,1.50,40.00,0.9); 35 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('United Kingdom',67886011,0.53,355839,281,241930,260650,1.80,40.00,0.87); 36 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('France',65273511,0.22,143783,119,547557,36527,1.90,42.00,0.84); 37 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Italy',60461826,-0.15,-88249,206,294140,148943,1.30,47.00,0.78); 38 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Tanzania',59734218,2.98,1728755,67,885800,-40076,4.90,18.00,0.77); 39 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('South Africa',59308690,1.28,750420,49,1213090,145405,2.40,28.00,0.76); 40 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Myanmar',54409800,0.67,364380,83,653290,-163313,2.20,29.00,0.7); 41 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Kenya',53771296,2.28,1197323,94,569140,-10000,3.50,20.00,0.69); 42 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('South Korea',51269185,0.09,43877,527,97230,11731,1.10,44.00,0.66); 43 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Colombia',50882891,1.08,543448,46,1109500,204796,1.80,31.00,0.65); 44 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Spain',46754778,0.04,18002,94,498800,40000,1.30,45.00,0.6); 45 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Uganda',45741007,3.32,1471413,229,199810,168694,5.00,17.00,0.59); 46 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Argentina',45195774,0.93,415097,17,2736690,4800,2.30,32.00,0.58); 47 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Algeria',43851044,1.85,797990,18,2381740,-10000,3.10,29.00,0.56); 48 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Sudan',43849260,2.42,1036022,25,1765048,-50000,4.40,20.00,0.56); 49 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Ukraine',43733762,-0.59,-259876,75,579320,10000,1.40,41.00,0.56); 50 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Iraq',40222493,2.32,912710,93,434320,7834,3.70,21.00,0.52); 51 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Afghanistan',38928346,2.33,886592,60,652860,-62920,4.60,18.00,0.5); 52 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Poland',37846611,-0.11,-41157,124,306230,-29395,1.40,42.00,0.49); 53 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Canada',37742154,0.89,331107,4,9093510,242032,1.50,41.00,0.48); 54 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Morocco',36910560,1.20,438791,83,446300,-51419,2.40,30.00,0.47); 55 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Saudi Arabia',34813871,1.59,545343,16,2149690,134979,2.30,32.00,0.45); 56 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Uzbekistan',33469203,1.48,487487,79,425400,-8863,2.40,28.00,0.43); 57 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Peru',32971854,1.42,461401,26,1280000,99069,2.30,31.00,0.42); 58 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Angola',32866272,3.27,1040977,26,1246700,6413,5.60,17.00,0.42); 59 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Malaysia',32365999,1.30,416222,99,328550,50000,2.00,30.00,0.42); 60 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mozambique',31255435,2.93,889399,40,786380,-5000,4.90,18.00,0.4); 61 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Ghana',31072940,2.15,655084,137,227540,-10000,3.90,22.00,0.4); 62 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Yemen',29825964,2.28,664042,56,527970,-30000,3.80,20.00,0.38); 63 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Nepal',29136808,1.85,528098,203,143350,41710,1.90,25.00,0.37); 64 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Venezuela',28435940,-0.28,-79889,32,882050,-653249,2.30,30.00,0.36); 65 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Madagascar',27691018,2.68,721711,48,581795,-1500,4.10,20.00,0.36); 66 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Cameroon',26545863,2.59,669483,56,472710,-4800,4.60,19.00,0.34); 67 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Côte d''Ivoire',26378274,2.57,661730,83,318000,-8000,4.70,19.00,0.34); 68 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('North Korea',25778816,0.44,112655,214,120410,-5403,1.90,35.00,0.33); 69 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Australia',25499884,1.18,296686,3,7682300,158246,1.80,38.00,0.33); 70 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Niger',24206644,3.84,895929,19,1266700,4000,7.00,15.00,0.31); 71 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Taiwan',23816775,0.18,42899,673,35410,30001,1.20,42.00,0.31); 72 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Sri Lanka',21413249,0.42,89516,341,62710,-97986,2.20,34.00,0.27); 73 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Burkina Faso',20903273,2.86,581895,76,273600,-25000,5.20,18.00,0.27); 74 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mali',20250833,3.02,592802,17,1220190,-40000,5.90,16.00,0.26); 75 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Romania',19237691,-0.66,-126866,84,230170,-73999,1.60,43.00,0.25); 76 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Malawi',19129952,2.69,501205,203,94280,-16053,4.30,18.00,0.25); 77 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Chile',19116201,0.87,164163,26,743532,111708,1.70,35.00,0.25); 78 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Kazakhstan',18776707,1.21,225280,7,2699700,-18000,2.80,31.00,0.24); 79 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Zambia',18383955,2.93,522925,25,743390,-8000,4.70,18.00,0.24); 80 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Guatemala',17915568,1.90,334096,167,107160,-9215,2.90,23.00,0.23); 81 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Ecuador',17643054,1.55,269392,71,248360,36400,2.40,28.00,0.23); 82 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Syria',17500658,2.52,430523,95,183630,-427391,2.80,26.00,0.22); 83 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Netherlands',17134872,0.22,37742,508,33720,16000,1.70,43.00,0.22); 84 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Senegal',16743927,2.75,447563,87,192530,-20000,4.70,19.00,0.21); 85 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Cambodia',16718965,1.41,232423,95,176520,-30000,2.50,26.00,0.21); 86 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Chad',16425864,3.00,478988,13,1259200,2000,5.80,17.00,0.21); 87 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Somalia',15893222,2.92,450317,25,627340,-40000,6.10,17.00,0.2); 88 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Zimbabwe',14862924,1.48,217456,38,386850,-116858,3.60,19.00,0.19); 89 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Guinea',13132795,2.83,361549,53,245720,-4000,4.70,18.00,0.17); 90 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Rwanda',12952218,2.58,325268,525,24670,-9000,4.10,20.00,0.17); 91 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Benin',12123200,2.73,322049,108,112760,-2000,4.90,19.00,0.16); 92 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Burundi',11890784,3.12,360204,463,25680,2001,5.50,17.00,0.15); 93 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Tunisia',11818619,1.06,123900,76,155360,-4000,2.20,33.00,0.15); 94 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bolivia',11673021,1.39,159921,11,1083300,-9504,2.80,26.00,0.15); 95 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Belgium',11589623,0.44,50295,383,30280,48000,1.70,42.00,0.15); 96 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Haiti',11402528,1.24,139451,414,27560,-35000,3.00,24.00,0.15); 97 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Cuba',11326616,-0.06,-6867,106,106440,-14400,1.60,42.00,0.15); 98 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('South Sudan',11193725,1.19,131612,18,610952,-174200,4.70,19.00,0.14); 99 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Dominican Republic',10847910,1.01,108952,225,48320,-30000,2.40,28.00,0.14); 100 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Czech Republic (Czechia)',10708981,0.18,19772,139,77240,22011,1.60,43.00,0.14); 101 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Greece',10423054,-0.48,-50401,81,128900,-16000,1.30,46.00,0.13); 102 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Jordan',10203134,1.00,101440,115,88780,10220,2.80,24.00,0.13); 103 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Portugal',10196709,-0.29,-29478,111,91590,-6000,1.30,46.00,0.13); 104 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Azerbaijan',10139177,0.91,91459,123,82658,1200,2.10,32.00,0.13); 105 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Sweden',10099265,0.63,62886,25,410340,40000,1.90,41.00,0.13); 106 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Honduras',9904607,1.63,158490,89,111890,-6800,2.50,24.00,0.13); 107 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('United Arab Emirates',9890402,1.23,119873,118,83600,40000,1.40,33.00,0.13); 108 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Hungary',9660351,-0.25,-24328,107,90530,6000,1.50,43.00,0.12); 109 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Tajikistan',9537645,2.32,216627,68,139960,-20000,3.60,22.00,0.12); 110 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Belarus',9449323,-0.03,-3088,47,202910,8730,1.70,40.00,0.12); 111 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Austria',9006398,0.57,51296,109,82409,65000,1.50,43.00,0.12); 112 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Papua New Guinea',8947024,1.95,170915,20,452860,-800,3.60,22.00,0.11); 113 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Serbia',8737371,-0.40,-34864,100,87460,4000,1.50,42.00,0.11); 114 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Israel',8655535,1.60,136158,400,21640,10000,3.00,30.00,0.11); 115 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Switzerland',8654622,0.74,63257,219,39516,52000,1.50,43.00,0.11); 116 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Togo',8278724,2.43,196358,152,54390,-2000,4.40,19.00,0.11); 117 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Sierra Leone',7976983,2.10,163768,111,72180,-4200,4.30,19.00,0.1); 118 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Hong Kong',7496981,0.82,60827,7140,1050,29308,1.30,45.00,0.1); 119 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Laos',7275560,1.48,106105,32,230800,-14704,2.70,24.00,0.09); 120 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Paraguay',7132538,1.25,87902,18,397300,-16556,2.40,26.00,0.09); 121 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bulgaria',6948445,-0.74,-51674,64,108560,-4800,1.60,45.00,0.09); 122 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Libya',6871292,1.38,93840,4,1759540,-1999,2.30,29.00,0.09); 123 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Lebanon',6825445,-0.44,-30268,667,10230,-30012,2.10,30.00,0.09); 124 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Nicaragua',6624554,1.21,79052,55,120340,-21272,2.40,26.00,0.08); 125 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Kyrgyzstan',6524195,1.69,108345,34,191800,-4000,3.00,26.00,0.08); 126 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('El Salvador',6486205,0.51,32652,313,20720,-40539,2.10,28.00,0.08); 127 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Turkmenistan',6031200,1.50,89111,13,469930,-5000,2.80,27.00,0.08); 128 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Singapore',5850342,0.79,46005,8358,700,27028,1.20,42.00,0.08); 129 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Denmark',5792202,0.35,20326,137,42430,15200,1.80,42.00,0.07); 130 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Finland',5540720,0.15,8564,18,303890,14000,1.50,43.00,0.07); 131 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Congo',5518087,2.56,137579,16,341500,-4000,4.50,19.00,0.07); 132 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Slovakia',5459642,0.05,2629,114,48088,1485,1.50,41.00,0.07); 133 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Norway',5421241,0.79,42384,15,365268,28000,1.70,40.00,0.07); 134 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Oman',5106626,2.65,131640,16,309500,87400,2.90,31.00,0.07); 135 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('State of Palestine',5101414,2.41,119994,847,6020,-10563,3.70,21.00,0.07); 136 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Costa Rica',5094118,0.92,46557,100,51060,4200,1.80,33.00,0.07); 137 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Liberia',5057681,2.44,120307,53,96320,-5000,4.40,19.00,0.06); 138 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Ireland',4937786,1.13,55291,72,68890,23604,1.80,38.00,0.06); 139 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Central African Republic',4829767,1.78,84582,8,622980,-40000,4.80,18.00,0.06); 140 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('New Zealand',4822233,0.82,39170,18,263310,14881,1.90,38.00,0.06); 141 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mauritania',4649658,2.74,123962,5,1030700,5000,4.60,20.00,0.06); 142 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Panama',4314767,1.61,68328,58,74340,11200,2.50,30.00,0.06); 143 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Kuwait',4270571,1.51,63488,240,17820,39520,2.10,37.00,0.05); 144 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Croatia',4105267,-0.61,-25037,73,55960,-8001,1.40,44.00,0.05); 145 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Moldova',4033963,-0.23,-9300,123,32850,-1387,1.30,38.00,0.05); 146 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Georgia',3989167,-0.19,-7598,57,69490,-10000,2.10,38.00,0.05); 147 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Eritrea',3546421,1.41,49304,35,101000,-39858,4.10,19.00,0.05); 148 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Uruguay',3473730,0.35,11996,20,175020,-3000,2.00,36.00,0.04); 149 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bosnia and Herzegovina',3280819,-0.61,-20181,64,51000,-21585,1.30,43.00,0.04); 150 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mongolia',3278290,1.65,53123,2,1553560,-852,2.90,28.00,0.04); 151 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Armenia',2963243,0.19,5512,104,28470,-4998,1.80,35.00,0.04); 152 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Jamaica',2961167,0.44,12888,273,10830,-11332,2.00,31.00,0.04); 153 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Qatar',2881053,1.73,48986,248,11610,40000,1.90,32.00,0.04); 154 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Albania',2877797,-0.11,-3120,105,27400,-14000,1.60,36.00,0.04); 155 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Puerto Rico',2860853,-2.47,-72555,323,8870,-97986,1.20,44.00,0.04); 156 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Lithuania',2722289,-1.35,-37338,43,62674,-32780,1.70,45.00,0.03); 157 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Namibia',2540905,1.86,46375,3,823290,-4806,3.40,22.00,0.03); 158 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Gambia',2416668,2.94,68962,239,10120,-3087,5.30,18.00,0.03); 159 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Botswana',2351627,2.08,47930,4,566730,3000,2.90,24.00,0.03); 160 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Gabon',2225734,2.45,53155,9,257670,3260,4.00,23.00,0.03); 161 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Lesotho',2142249,0.80,16981,71,30360,-10047,3.20,24.00,0.03); 162 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('North Macedonia',2083374,0.00,-85,83,25220,-1000,1.50,39.00,0.03); 163 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Slovenia',2078938,0.01,284,103,20140,2000,1.60,45.00,0.03); 164 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Guinea-Bissau',1968001,2.45,47079,70,28120,-1399,4.50,19.00,0.03); 165 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Latvia',1886198,-1.08,-20545,30,62200,-14837,1.70,44.00,0.02); 166 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bahrain',1701575,3.68,60403,2239,760,47800,2.00,32.00,0.02); 167 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Equatorial Guinea',1402985,3.47,46999,50,28050,16000,4.60,22.00,0.02); 168 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Trinidad and Tobago',1399488,0.32,4515,273,5130,-800,1.70,36.00,0.02); 169 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Estonia',1326535,0.07,887,31,42390,3911,1.60,42.00,0.02); 170 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Timor-Leste',1318445,1.96,25326,89,14870,-5385,4.10,21.00,0.02); 171 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mauritius',1271768,0.17,2100,626,2030,0,1.40,37.00,0.02); 172 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Cyprus',1207359,0.73,8784,131,9240,5000,1.30,37.00,0.02); 173 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Eswatini',1160164,1.05,12034,67,17200,-8353,3.00,21.00,0.01); 174 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Djibouti',988000,1.48,14440,43,23180,900,2.80,27.00,0.01); 175 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Fiji',896445,0.73,6492,49,18270,-6202,2.80,28.00,0.01); 176 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Réunion',895312,0.72,6385,358,2500,-1256,2.30,36.00,0.01); 177 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Comoros',869601,2.20,18715,467,1861,-2000,4.20,20.00,0.01); 178 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Guyana',786552,0.48,3786,4,196850,-6000,2.50,27.00,0.01); 179 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bhutan',771608,1.12,8516,20,38117,320,2.00,28.00,0.01); 180 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Solomon Islands',686884,2.55,17061,25,27990,-1600,4.40,20.00,0.01); 181 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Macao',649335,1.39,8890,21645,30,5000,1.20,39.00,0.01); 182 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Montenegro',628066,0.01,79,47,13450,-480,1.80,39.00,0.01); 183 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Luxembourg',625978,1.66,10249,242,2590,9741,1.50,40.00,0.01); 184 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Western Sahara',597339,2.55,14876,2,266000,5582,2.40,28.00,0.01); 185 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Suriname',586632,0.90,5260,4,156000,-1000,2.40,29.00,0.01); 186 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Cabo Verde',555987,1.10,6052,138,4030,-1342,2.30,28.00,0.01); 187 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Maldives',540544,1.81,9591,1802,300,11370,1.90,30.00,0.01); 188 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Malta',441543,0.27,1171,1380,320,900,1.50,43.00,0.01); 189 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Brunei',437479,0.97,4194,83,5270,0,1.80,32.00,0.01); 190 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Guadeloupe',400124,0.02,68,237,1690,-1440,2.20,44.00,0.01); 191 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Belize',397628,1.86,7275,17,22810,1200,2.30,25.00,0.01); 192 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Bahamas',393244,0.97,3762,39,10010,1000,1.80,32.00,0.01); 193 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Martinique',375265,-0.08,-289,354,1060,-960,1.90,47.00,0); 194 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Iceland',341243,0.65,2212,3,100250,380,1.80,37.00,0); 195 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Vanuatu',307145,2.42,7263,25,12190,120,3.80,21.00,0); 196 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('French Guiana',298682,2.70,7850,4,82200,1200,3.40,25.00,0); 197 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Barbados',287375,0.12,350,668,430,-79,1.60,40.00,0); 198 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('New Caledonia',285498,0.97,2748,16,18280,502,2.00,34.00,0); 199 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('French Polynesia',280908,0.58,1621,77,3660,-1000,2.00,34.00,0); 200 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Mayotte',272815,2.50,6665,728,375,0,3.70,20.00,0); 201 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Sao Tome & Principe',219159,1.91,4103,228,960,-1680,4.40,19.00,0); 202 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Samoa',198414,0.67,1317,70,2830,-2803,3.90,22.00,0); 203 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Saint Lucia',183627,0.46,837,301,610,0,1.40,34.00,0); 204 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Channel Islands',173863,0.93,1604,915,190,1351,1.50,43.00,0); 205 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Guam',168775,0.89,1481,313,540,-506,2.30,31.00,0); 206 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Curaçao',164093,0.41,669,370,444,515,1.80,42.00,0); 207 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Kiribati',119449,1.57,1843,147,810,-800,3.60,23.00,0); 208 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Micronesia',115023,1.06,1208,164,700,-600,3.10,24.00,0); 209 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Grenada',112523,0.46,520,331,340,-200,2.10,32.00,0); 210 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('St. Vincent & Grenadines',110940,0.32,351,284,390,-200,1.90,33.00,0); 211 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Aruba',106766,0.43,452,593,180,201,1.90,41.00,0); 212 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Tonga',105695,1.15,1201,147,720,-800,3.60,22.00,0); 213 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('U.S. Virgin Islands',104425,-0.15,-153,298,350,-451,2.00,43.00,0); 214 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Seychelles',98347,0.62,608,214,460,-200,2.50,34.00,0); 215 | INSERT INTO countries(name,population,percent_one_year_change,population_change,density_per_sq_km,area_sq_km,net_migrants,fertility_rate,median_age,percent_of_world_pop) VALUES ('Antigua and Barbuda',97929,0.84,811,223,440,0,2.00,34.00,0); 216 | 217 | --Display countries with a population greater than 10 million and order by population 218 | SELECT name, population FROM countries 219 | WHERE population > 10000000 220 | ORDER BY population DESC; 221 | 222 | --Group countries by population using CASE 223 | SELECT name, 224 | CASE 225 | WHEN population > 10000000 THEN "above 10 million" 226 | WHEN population > 1000000 THEN "1-10 million" 227 | WHEN population > 100000 THEN "100,000-1 million" 228 | WHEN population > 10000 THEN "10,000-100,000" 229 | ELSE "below 10,000" 230 | END "population group" 231 | FROM countries 232 | ORDER BY population DESC; 233 | 234 | --What is the median age in countries with the highest fertility rates? 235 | SELECT name, fertility_rate, median_age FROM countries 236 | WHERE fertility_rate > 3 237 | ORDER BY fertility_rate DESC; 238 | 239 | --Which countries have the fastest-growing populations this year? 240 | SELECT name AS "fastest-growing populations", percent_one_year_change AS "one year population change (%)" FROM countries 241 | WHERE percent_one_year_change > 2 242 | ORDER BY percent_one_year_change DESC; 243 | --------------------------------------------------------------------------------