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
447 changes: 447 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions 1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT pc.model, pc.speed, pc.hd FROM PC
INNER JOIN product
ON pc.model=product.model
WHERE pc.hd = 10 AND maker='A' OR pc.hd = 20 AND maker='A'
ORDER BY pc.speed;
8 changes: 8 additions & 0 deletions 10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SELECT type, product.model, MAX(price) AS max_price
FROM (SELECT model, price
FROM pc
UNION SELECT model, price
FROM printer
UNION SELECT model, price
FROM laptop) AS product_any JOIN product ON product_any.model = product.model
GROUP BY product.model
2 changes: 2 additions & 0 deletions 2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT * FROM outcome_o
WHERE date LIKE '____-__-14%';
4 changes: 4 additions & 0 deletions 3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT maker
FROM product JOIN pc ON pc.model = product.model
GROUP BY maker
HAVING MIN(speed)>=600;
4 changes: 4 additions & 0 deletions 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT maker
FROM product LEFT JOIN pc ON pc.model = product.model
WHERE pc.model is null and type='PC'
GROUP BY maker;
9 changes: 9 additions & 0 deletions 5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT maker
FROM product
WHERE EXISTS (
SELECT maker
FROM product AS all_products LEFT JOIN pc ON pc.model = all_products.model
WHERE type = 'PC' AND product.maker = all_products.maker
GROUP BY maker
HAVING COUNT(all_products.model) = COUNT(pc.model))
GROUP BY maker;
4 changes: 4 additions & 0 deletions 6.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT CONCAT('name: ', name) AS name,
CONCAT('class: ', class) AS class,
CONCAT('launched: ', launched) AS launched
FROM ships
5 changes: 5 additions & 0 deletions 7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SELECT maker
FROM product LEFT JOIN pc ON pc.model = product.model
WHERE type='PC'
GROUP BY maker
HAVING COUNT(pc.model) BETWEEN 1 AND COUNT(product.model) - 1;
6 changes: 6 additions & 0 deletions 8.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SELECT ship,
(SELECT classes.country FROM ships JOIN classes ON
outcomes.ship = ships.name AND ships.class = classes.class) AS country
FROM outcomes
WHERE result='sunk' AND
(SELECT ships.name FROM ships WHERE outcomes.ship = ships.name) IS NOT NULL;
9 changes: 9 additions & 0 deletions 9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SELECT maker,
IF(product_pc=0, 'no', CONCAT('yes(', available_pc, ')')) AS creates_pc
FROM(SELECT maker, CASE WHEN product.type='PC' THEN 1 ELSE 0 END AS
product_pc, COUNT(available_models.model) as available_pc
FROM product
LEFT JOIN (SELECT model FROM pc) AS available_models ON
available_models.model = product.model
GROUP BY maker) AS products_pc
ORDER BY maker;
Loading