Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions khan-academy/advanced_sql_queries.sql
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
-- Solution SQL for the project from the Advanced SQL queries course ("Data dig")
/* Put your data in here and query it! */

/* We’ve curated a set of interesting data sets for you: Top movies, Top countries by population, Solar system objects by size, Marvel characters, Furniture store sales, Earned KA badges, Winston's donut logs, Card game results, and NFL draft picks.

Pick one of those data sets or create a data set like that, and use advanced SELECT queries to discover things about the data. What sort of questions might one have about that data, like if they were using it for an app or a business idea? Here are some ideas:*/


CREATE TABLE marvels (ID INTEGER PRIMARY KEY,
name TEXT,
popularity INTEGER,
alignment TEXT,
gender TEXT,
height_m NUMERIC,
weight_kg NUMERIC,
hometown TEXT,
intelligence INTEGER,
strength INTEGER,
speed INTEGER,
durability INTEGER,
energy_Projection INTEGER,
fighting_Skills INTEGER);

INSERT INTO marvels VALUES(1, "Spider Man", 1, "Good", "Male", 1.78, 75.75, "USA", 4, 4, 3, 3, 1, 4);
INSERT INTO marvels VALUES(2, "Iron Man", 20, "Neutral", "Male", 1.98, 102.58, "USA", 6, 6, 5, 6, 6, 4);
INSERT INTO marvels VALUES(3, "Hulk", 18, "Neutral", "Male", 2.44, 635.29, "USA", 6, 7, 3, 7, 5, 4);
INSERT INTO marvels VALUES(4, "Wolverine", 3, "Good", "Male", 1.6, 88.46, "Canada", 2, 4, 2, 4, 1, 7);
INSERT INTO marvels VALUES(5, "Thor", 5, "Good", "Male", 1.98, 290.3, "Norway", 2, 7, 7, 6, 6, 4);
INSERT INTO marvels VALUES(6, "Green Goblin", 91, "Bad", "Male", 1.93, 174.63, "USA", 4, 4, 3, 4, 3, 3);
INSERT INTO marvels VALUES(7, "Magneto", 11, "Neutral", "Male", 1.88, 86.18, "Germany", 6, 3, 5, 4, 6, 4);
INSERT INTO marvels VALUES(8, "Thanos", 47, "Bad", "Male", 2.01, 446.79, "Titan", 6, 7, 7, 6, 6, 4);
INSERT INTO marvels VALUES(9, "Loki", 32, "Bad", "Male", 1.93, 238.14, "Jotunheim", 5, 5, 7, 6, 6, 3);
INSERT INTO marvels VALUES(10, "Doctor Doom", 19, "Bad", "Male", 2.01, 188.24, "Latveria", 6, 4, 5, 6, 6, 4);
INSERT INTO marvels VALUES(11, "Jean Greay", 8, "Good", "Female", 1.68, 52.16, "USA", 3, 2, 7, 7, 7, 4);
INSERT INTO marvels VALUES(12, "Rogue", 4, "Good", "Female", 1.73, 54.43, "USA", 7, 7, 7, 7, 7, 7);


SELECT name, popularity FROM marvels GROUP BY popularity;
SELECT name FROM marvels WHERE durability > 50 GROUP BY fighting_skills;

SELECT name,
CASE
WHEN height_m < 2 THEN "Your short"
WHEN height_m > 2 THEN "Your tall"
ELSE "Super Heros Can't Jump"
END AS Tall_or_short
FROM marvels GROUP BY name;

SELECT name FROM marvels WHERE id < 13 AND id > 5 AND gender = "female";

SELECT SUM(energy_Projection) AS energy_total FROM marvels;
17 changes: 17 additions & 0 deletions khan-academy/modifying_databases.sql
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
-- Solution SQL for the project from the Modifying databases with SQL course ("App impersonator")

CREATE TABLE player(id INTEGER PRIMARY KEY, name TEXT, item TEXT, gender TEXT, age INTEGER);

INSERT INTO player VALUES(1,"Briy", "Laptop", "Female", 29);
INSERT INTO player VALUES(2, "Johnny", "Book of Spells", "Male", 33 );
INSERT INTO player VALUES(3, "Stacy", "Stick", "Female", 27);
INSERT INTO player VALUES(4, "Billy", "Gun", "Male", 28);
INSERT INTO player VALUES(5, "Sandra", "Bullets", "Male", 25);

UPDATE player
SET gender = "Female"
WHERE id = 5;
UPDATE player
SET age = 22, name = "Brenda", gender = "Female", item = "Camera"
WHERE id = 4;
DELETE player
WHERE id = 2;
28 changes: 28 additions & 0 deletions khan-academy/relational_queries.sql
Original file line number Diff line number Diff line change
@@ -1 +1,29 @@
-- Solution SQL for the project from the Relational Queries course ("Famous people")


/* Create table about the people and what they do here */
CREATE TABLE person (id INTEGER PRIMARY KEY, name TEXT, year_born INTEGER, birthplace TEXT, gender TEXT);

CREATE TABLE person_Info(id INTEGER PRIMARY KEY, year_died INTEGER, occupation TEXT, still_alive TEXT, full_name TEXT);

INSERT INTO person VALUES(1, "Aaliyah", 1979, "Brooklyn, NY", "Female");
INSERT INTO person VALUES(2, "Wallace", 1857, "Bridgewter, VT", "Male");
INSERT INTO person VALUES(3, "Shirley", 1933, "New York City, NY", "Female");
INSERT INTO person VALUES(4, "Bruce", 1943, "New York City, NY", "Male");
INSERT INTO person VALUES(5, "Don", 1926, "New York City, NY", "Male");
INSERT INTO person VALUES(6, "Oleta", 1962, "Seatle, WA", "Female");
INSERT INTO person VALUES(7, "Scott", 1957, "Windham,NY", "Male");
INSERT INTO person VALUES(8, "Leona", 1973, "St. Louis, MO", "Female");

INSERT INTO person_Info VALUES(1, 2001, "Singer/Actor", "NO", "Aaliyah Dana Haughton");
INSERT INTO person_Info VALUES(2, 1921, "Docotr", "NO", "Wallace Calvin Abbot");
INSERT INTO person_Info VALUES(3, NULL, "Judge", "YES", "Shirley S. Abrahamson");
INSERT INTO person_Info VALUES(4, NULL, "Legal Scholar", "YES", "Bruce Ackerman");
INSERT INTO person_Info VALUES(5, 2005, "Actor/Comic", "NO", "Don Adams");
INSERT INTO person_Info VALUES(6, NULL, "Singer", "YES", "Oleta Adams");
INSERT INTO person_Info VALUES(7, NULL, "Cartoonist", "YES", "Scott Adams");
INSERT INTO person_Info VALUES(8, 1973, "Actor", "NO", "Leona Anderson");

SELECT year_born, still_alive
FROM person JOIN person_Info
ON name = full_name;
43 changes: 43 additions & 0 deletions khan-academy/sql_basics.sql
Original file line number Diff line number Diff line change
@@ -1 +1,44 @@
-- Solution SQL for the project from the SQL Basics course ("Design a store database")

/* Challenge: Design a store database*/
/* Instructions: Create a database with items for a store. Create your own store! Your store should sell one type of things, like clothing or bikes, whatever you want your store to specialize in. You should have a table for all the items in your store, and at least 5 columns for the kind of data you think you'd need to store. You should sell at least 15 items, and use select statements to order your items by price and show at least one statistic about the items. */

/*CREATES TABLES*/
CREATE TABLE my_store (id INTEGER PRIMARY KEY, item TEXT, color TEXT, size TEXT, quantity INTEGER, cost INTEGER);
/*INFO IN MY TABLE -- SHIRTS*/
INSERT INTO my_store VALUES (1, "shirt", "red", "M", 5, 6.50 );
INSERT INTO my_store VALUES (2, "shirt", "blue", "L", 8, 7.50);
INSERT INTO my_store VALUES (3, "shirt", "green", "L", 10, 7.50);
INSERT INTO my_store VALUES (4, "shirt", "purple", "M", 7, 6.50);
INSERT INTO my_store VALUES (5, "shirt", "yellow", "L", 8, 7.50);
INSERT INTO my_store VALUES (6, "shirt", "blue", "M", 12, 6.50);
INSERT INTO my_store VALUES (7, "shirt", "blue", "S", 15, 5.50);
INSERT INTO my_store VALUES (8, "shirt", "green", "S", 8, 5.50);
INSERT INTO my_store VALUES (9, "shirt", "purple", "L", 12, 7.50);
INSERT INTO my_store VALUES (10, "shirt", "yellow", "S", 4, 5.50);
INSERT INTO my_store VALUES (11, "shirt", "pink", "M", 14, 6.50);
INSERT INTO my_store VALUES (12, "shirt", "orange", "L", 1, 7.50);
INSERT INTO my_store VALUES (13, "shirt", "orange", "S", 5, 5.50);
INSERT INTO my_store VALUES (14, "shirt", "pink", "L", 10, 7.50);
INSERT INTO my_store VALUES (15, "shirt", "black", "M", 10, 6.50);

INSERT INTO my_store VALUES (16, "pants", "red", "S", 5, 22.50 );
INSERT INTO my_store VALUES (17, "pants", "red", "M", 7, 32.50 );
INSERT INTO my_store VALUES (18, "pants", "red", "L", 10, 42.50 );
INSERT INTO my_store VALUES (19, "pants", "green", "S", 11, 22.50 );
INSERT INTO my_store VALUES (20, "pants", "green", "M", 5, 32.50 );
INSERT INTO my_store VALUES (21, "pants", "green", "L", 9, 42.50 );
INSERT INTO my_store VALUES (22, "pants", "blue", "S", 3, 22.50 );
INSERT INTO my_store VALUES (23, "pants", "blue", "M", 12, 32.50 );
INSERT INTO my_store VALUES (24, "pants", "blue", "L", 14, 42.50 );
INSERT INTO my_store VALUES (25, "pants", "purple", "S", 6, 22.50 );
INSERT INTO my_store VALUES (26, "pants", "purple", "M", 4, 32.50 );
INSERT INTO my_store VALUES (27, "pants", "purple", "L", 9, 42.50 );
INSERT INTO my_store VALUES (28, "pants", "yellow", "S", 7, 22.50 );
INSERT INTO my_store VALUES (29, "pants", "yellow", "M", 12, 32.50 );
INSERT INTO my_store VALUES (30, "pants", "yellow", "L", 19, 42.50 );

SELECT size, item, cost FROM my_store;
SELECT item, color FROM my_store;
SELECT color, size, item FROM my_store WHERE quantity > 8 AND cost > 7 GROUP BY cost;
SELECT AVG(cost) FROM my_store WHERE item = "pants";