movies and kosten

This commit is contained in:
git-sandro 2026-02-12 17:04:16 +01:00
parent 33dcdcbb84
commit 9ac368847b
5 changed files with 48 additions and 12 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

13
kosten/create_table.sql Normal file
View 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);

View 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;

View File

@ -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,
score INTEGER,
title CHARACTER VARYING NOT NULL
);*/
);
/*INSERT INTO movies (id, year, score, title) VALUES
(1, 1976, 99, 'Taxi Driver'),
(2, 1978, 93, 'The Deer Hunter'),
(3, 1985, 98, 'Brazil'),
(4, 1990, 96, 'Goodfellas'),
(5, 1991, 76, 'Cape Fear'),
(6, 1995, 80, 'Casino'),
(7, 1995, 86, 'Heat'),
(8, 2000, 84, 'Meet the Parents');*/
INSERT INTO movies (id, year, score, title) VALUES
(1, 1976, 99, 'Taxi Driver'),
(2, 1978, 93, 'The Deer Hunter'),
(3, 1985, 98, 'Brazil'),
(4, 1990, 96, 'Goodfellas'),
(5, 1991, 76, 'Cape Fear'),
(6, 1995, 80, 'Casino'),
(7, 1995, 86, 'Heat'),
(8, 2000, 84, 'Meet the Parents');
SELECT * FROM movies

3
movies/select_basics.sql Normal file
View File

@ -0,0 +1,3 @@
SELECT title FROM movies;
SELECT title, year FROM movies;
SELECT year%100 AS "Jahrzehnt", title FROM movies;