sql
This commit is contained in:
parent
0f3005cd8e
commit
522e144ca3
@ -20,3 +20,6 @@ GIT Repository for for the Module CDS-104
|
||||
## GROUP BY
|
||||
|
||||
## HAVING
|
||||
|
||||
## JOIN
|
||||
|
||||
|
||||
BIN
movies/.DS_Store
vendored
Normal file
BIN
movies/.DS_Store
vendored
Normal file
Binary file not shown.
1
movies/order_by.sql
Normal file
1
movies/order_by.sql
Normal file
@ -0,0 +1 @@
|
||||
SELECT * FROM movies ORDER BY title DESC;
|
||||
BIN
murder_mystery/murder_mystery
Normal file
BIN
murder_mystery/murder_mystery
Normal file
Binary file not shown.
21
murder_mystery/querys.sql
Normal file
21
murder_mystery/querys.sql
Normal file
@ -0,0 +1,21 @@
|
||||
SELECT * FROM crime_scene_report WHERE city = 'SQL City' AND date = 20180115 AND type = 'murder';
|
||||
-- Security footage shows that there were 2 witnesses. The first witness lives at the last house on "Northwestern Dr".
|
||||
-- The second witness, named Annabel, lives somewhere on "Franklin Ave".
|
||||
|
||||
-- first witness
|
||||
SELECT * FROM person WHERE address_street_name = 'Northwestern Dr' ORDER BY address_number DESC LIMIT 1;
|
||||
-- id 14887 name Morty Schapiro license_id 118009 ssn 111564949
|
||||
|
||||
SELECT transcript FROM interview WHERE person_id = 14887;
|
||||
-- I heard a gunshot and then saw a man run out. He had a "Get Fit Now Gym" bag. The membership number on the bag started with "48Z".
|
||||
-- Only gold members have those bags. The man got into a car with a plate that included "H42W".
|
||||
|
||||
SELECT * FROM get_fit_now_member WHERE id LIKE '48Z%' AND membership_status = 'gold';
|
||||
SELECT * FROM drivers_license WHERE plate_number LIKE '%H42W%';
|
||||
|
||||
-- second witness
|
||||
SELECT * FROM person WHERE name LIKE '%Annabel%' AND address_street_name = 'Franklin Ave';
|
||||
-- id 16371 name Annabel Miller license_id 490173 ssn 318771143
|
||||
SELECT transcript FROM interview WHERE person_id = 16371;
|
||||
-- I saw the murder happen, and I recognized the killer from my gym when I was working out last week on January the 9th.
|
||||
SELECT * FROM get_fit_now_check_in WHERE check_in_date = 20180109 AND membership_id LIKE '48Z%'
|
||||
BIN
normalformen/Übung_NF.xlsx
Normal file
BIN
normalformen/Übung_NF.xlsx
Normal file
Binary file not shown.
59
shop/ctreate_table.sql
Normal file
59
shop/ctreate_table.sql
Normal file
@ -0,0 +1,59 @@
|
||||
/*CREATE TABLE kunde
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
vorname CHARACTER VARYING NOT NULL,
|
||||
name CHARACTER VARYING NOT NULL,
|
||||
email CHARACTER VARYING NOT NULL,
|
||||
passwort CHARACTER VARYING NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE bestellung
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
datum DATE
|
||||
);
|
||||
|
||||
CREATE TABLE bestellposition
|
||||
(
|
||||
bestellung_id INTEGER,
|
||||
produkt_id INTEGER,
|
||||
anzahl INTEGER
|
||||
);
|
||||
|
||||
CREATE TABLE produkte
|
||||
(
|
||||
id SERIAL PRIMARY KEY,
|
||||
name CHARACTER VARYING NOT NULL,
|
||||
beschreibung CHARACTER VARYING NOT NULL,
|
||||
preis NUMERIC(8,2) NOT NULL,
|
||||
lagerbestand INTEGER NOT NULL
|
||||
);*/
|
||||
|
||||
CREATE TABLE kunde
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
name CHARACTER VARYING NOT NULL,
|
||||
email CHARACTER VARYING NOT NULL,
|
||||
password CHARACTER VARYING NOT NULL
|
||||
);
|
||||
CREATE TABLE bestellung
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
kunde_id INTEGER NOT NULL,
|
||||
datum DATE NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE produkt
|
||||
(
|
||||
id INTEGER PRIMARY KEY,
|
||||
name CHARACTER VARYING NOT NULL,
|
||||
beschreibung CHARACTER VARYING NOT NULL,
|
||||
anzahl INTEGER NOT NULL,
|
||||
preis NUMERIC(8,2) NOT NULL
|
||||
);
|
||||
CREATE TABLE bestellung_produkt
|
||||
(
|
||||
bestellung_id INTEGER NOT NULL,
|
||||
produkt_id INTEGER NOT NULL,
|
||||
anzahl INTEGER NOT NULL
|
||||
);
|
||||
20
shop/insert.sql
Normal file
20
shop/insert.sql
Normal file
@ -0,0 +1,20 @@
|
||||
INSERT INTO kunde VALUES
|
||||
(1, 'Ingmar', 'ingmar@example.com', 'FN239v_d32%nsej3'),
|
||||
(3, 'Maria', 'maria@example.com', 'abc_%&'),
|
||||
(4, 'John', 'john@example.com', 'KeepCalm'),
|
||||
(2, 'Peter', 'peter@example.com', 'lskdfjlskdfj');
|
||||
INSERT INTO produkt VALUES
|
||||
(1, 'Keyboard', 'QUERTZ', 12, 29.99),
|
||||
(2, 'Notebook', 'Standard', 1, 1299.00),
|
||||
(3, 'Monitor', 'Flat', 5, 389.90),
|
||||
(4, 'Maus', 'Kabellos', 2, 19.00);
|
||||
INSERT INTO bestellung VALUES
|
||||
(1, 1, '2022-01-03'),
|
||||
(2, 1, '2022-01-07'),
|
||||
(3, 2, '2022-01-09');
|
||||
INSERT INTO bestellung_produkt VALUES
|
||||
(1, 1, 2),
|
||||
(1, 2, 1),
|
||||
(2, 3, 4),
|
||||
(3, 2, 2),
|
||||
(3, 4, 1);
|
||||
10
shop/join.sql
Normal file
10
shop/join.sql
Normal file
@ -0,0 +1,10 @@
|
||||
SELECT bestellung.id, kunde.name
|
||||
FROM bestellung
|
||||
JOIN kunde ON kunde.id = bestellung.kunde_id;
|
||||
|
||||
SELECT produkt.id, produkt.name, bestellung_produkt.anzahl
|
||||
FROM produkt
|
||||
JOIN bestellung_produkt ON produkt.id = bestellung_produkt.bestellung_id;
|
||||
|
||||
SELECT * FROM bestellung, produkt
|
||||
JOIN bestellung_produkt on bestellung.id = bestellung_produkt.bestellung_id;
|
||||
Loading…
x
Reference in New Issue
Block a user