Skip to content

Commit 9a4d804

Browse files
committed
Add the completed Computer Store Database project to the SQL with Python track.
1 parent bf2fb1a commit 9a4d804

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
-- Create the Product table
2+
CREATE TABLE Product (
3+
maker VARCHAR(50) NOT NULL,
4+
model INT NOT NULL,
5+
type VARCHAR(50) NOT NULL,
6+
PRIMARY KEY (model)
7+
);
8+
9+
-- Create the PC table
10+
CREATE TABLE PC (
11+
code INT NOT NULL,
12+
model INT NOT NULL,
13+
speed INT NOT NULL,
14+
ram INT NOT NULL,
15+
hd INT NOT NULL,
16+
cd VARCHAR(50) NOT NULL,
17+
price DECIMAL(10, 2) NOT NULL,
18+
PRIMARY KEY (code),
19+
FOREIGN KEY (model) REFERENCES Product(model)
20+
);
21+
22+
-- Create the Laptop table
23+
CREATE TABLE Laptop (
24+
code INT NOT NULL,
25+
model INT NOT NULL,
26+
speed INT NOT NULL,
27+
ram INT NOT NULL,
28+
hd INT NOT NULL,
29+
screen INT NOT NULL,
30+
price DECIMAL(10, 2) NOT NULL,
31+
PRIMARY KEY (code),
32+
FOREIGN KEY (model) REFERENCES Product(model)
33+
);
34+
35+
-- Create the Printer table
36+
CREATE TABLE Printer (
37+
code INT NOT NULL,
38+
model INT NOT NULL,
39+
color CHAR(1) NOT NULL,
40+
type VARCHAR(50) NOT NULL,
41+
price DECIMAL(10, 2) NOT NULL,
42+
PRIMARY KEY (code),
43+
FOREIGN KEY (model) REFERENCES Product(model)
44+
);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- stage 1 completed
2+
SELECT model,
3+
type,
4+
price
5+
FROM Printer
6+
WHERE price > 200;
7+
8+
-- stage 2 completed
9+
SELECT p.maker, p.model, l.hd, l.speed, l.price
10+
FROM Product AS p
11+
INNER JOIN Laptop AS l
12+
ON p.model = l.model
13+
WHERE l.hd >= 1000
14+
ORDER BY l.hd ASC, l.speed DESC, l.price ASC;
15+
16+
-- stage 3 completed
17+
SELECT COUNT(p1.maker) as number_of_unique_makers
18+
FROM Product AS p1
19+
WHERE (SELECT COUNT(p2.model) FROM Product AS p2
20+
WHERE p2.maker = p1.maker) = 1;
21+
22+
-- stage 4 completed
23+
WITH all_prices AS (
24+
SELECT a.maker, a.model, b.speed, b.price
25+
FROM Product a INNER JOIN PC b
26+
ON a.model = b.model
27+
28+
UNION
29+
30+
SELECT a.maker, a.model, b.speed, b.price
31+
FROM Product a INNER JOIN Laptop b
32+
ON a.model = b.model
33+
),
34+
lowest_prices AS (
35+
SELECT r.maker AS maker, r.model AS model, r.speed AS speed, r.price AS price
36+
FROM all_prices r HAVING speed = ( SELECT MIN(speed) FROM all_prices )
37+
)
38+
SELECT * FROM lowest_prices;

0 commit comments

Comments
 (0)