movies and kosten
This commit is contained in:
parent
33dcdcbb84
commit
9ac368847b
13
kosten/create_table.sql
Normal file
13
kosten/create_table.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE kosten
|
||||||
|
(
|
||||||
|
beschreibung CHARACTER VARYING,
|
||||||
|
projekt_id INTEGER,
|
||||||
|
betrag NUMERIC(6,2)
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO kosten VALUES
|
||||||
|
('Telefon', 1, 98.5),
|
||||||
|
('Reisekosten', 1, 466.20),
|
||||||
|
('Material', 1, 235.60),
|
||||||
|
('Reisekosten', 2, 120.60),
|
||||||
|
('Material', 2, 32.20);
|
||||||
18
kosten/select_exercise.sql
Normal file
18
kosten/select_exercise.sql
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
-- Selektieren Sie die Summe der Kosten pro Projekt
|
||||||
|
SELECT projekt_id, sum(betrag)
|
||||||
|
FROM kosten
|
||||||
|
GROUP BY projekt_id;
|
||||||
|
|
||||||
|
-- Selektieren Sie die höchsten und niedrigsten Positionen für jede Kategorie ("Beschreibung")
|
||||||
|
SELECT beschreibung, min(betrag), max(betrag)
|
||||||
|
FROM kosten
|
||||||
|
GROUP BY beschreibung;
|
||||||
|
|
||||||
|
-- Zählen Sie (mit SQL) die Anzahl Zeilen in der Tabelle "Kosten" (verwenden Sie COUNT ohne GROUP BY)
|
||||||
|
SELECT COUNT(projekt_id)
|
||||||
|
FROM kosten;
|
||||||
|
|
||||||
|
-- Erzeugen Sie eine Übersichtstabelle: Projekt, Liste der Beschreibungen (Tipp: string_agg)
|
||||||
|
SELECT projekt_id, SUM(betrag), STRING_AGG(beschreibung, ',')
|
||||||
|
FROM kosten
|
||||||
|
GROUP BY projekt_id;
|
||||||
@ -1,19 +1,21 @@
|
|||||||
/*CREATE TABLE movies
|
DROP TABLE IF EXISTS movies;
|
||||||
|
|
||||||
|
CREATE TABLE movies
|
||||||
(
|
(
|
||||||
id INTEGER PRIMARY KEY,
|
id INTEGER PRIMARY KEY, /*Use SERIAL for auto increment*/
|
||||||
year INTEGER,
|
year INTEGER,
|
||||||
score INTEGER,
|
score INTEGER,
|
||||||
title CHARACTER VARYING NOT NULL
|
title CHARACTER VARYING NOT NULL
|
||||||
);*/
|
);
|
||||||
|
|
||||||
/*INSERT INTO movies (id, year, score, title) VALUES
|
INSERT INTO movies (id, year, score, title) VALUES
|
||||||
(1, 1976, 99, 'Taxi Driver'),
|
(1, 1976, 99, 'Taxi Driver'),
|
||||||
(2, 1978, 93, 'The Deer Hunter'),
|
(2, 1978, 93, 'The Deer Hunter'),
|
||||||
(3, 1985, 98, 'Brazil'),
|
(3, 1985, 98, 'Brazil'),
|
||||||
(4, 1990, 96, 'Goodfellas'),
|
(4, 1990, 96, 'Goodfellas'),
|
||||||
(5, 1991, 76, 'Cape Fear'),
|
(5, 1991, 76, 'Cape Fear'),
|
||||||
(6, 1995, 80, 'Casino'),
|
(6, 1995, 80, 'Casino'),
|
||||||
(7, 1995, 86, 'Heat'),
|
(7, 1995, 86, 'Heat'),
|
||||||
(8, 2000, 84, 'Meet the Parents');*/
|
(8, 2000, 84, 'Meet the Parents');
|
||||||
|
|
||||||
SELECT * FROM movies
|
SELECT * FROM movies
|
||||||
3
movies/select_basics.sql
Normal file
3
movies/select_basics.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
SELECT title FROM movies;
|
||||||
|
SELECT title, year FROM movies;
|
||||||
|
SELECT year%100 AS "Jahrzehnt", title FROM movies;
|
||||||
Loading…
x
Reference in New Issue
Block a user