Selektion | Spalten |
---|---|
Filterung | Zeilen |
Sortierung | Reihenfolge |
SELECT ausgabespalten
FROM tabelle
WHERE bedingung
ORDER BY spaltennamen
SELECT name, vorname, gehalt
FROM mitarbeiter
WHERE oeid=14
ORDER BY gehalt;
SELECT name, vorname, gehalt
FROM mitarbeiter
WHERE oeid=14
ORDER BY gehalt desc;
SELECT *
FROM mitarbeiter;
Ausgabe der gesamten Tabelle, d.h. alle Zeilen und alle Spalten
SELECT
name, vorname,
extract(year FROM eintrittsdatum)
AS eintrittsjahr
FROM mitarbeiter
WHERE oeid=14;
SELECT
name, vorname,
extract(year FROM current_date) -
extract(year FROM eintrittsdatum)
AS beschaeftigungsjahre
FROM mitarbeiter
WHERE oeid=14;
SELECT
name, vorname, gehalt
FROM mitarbeiter
WHERE
gehalt < 35000 AND
eintrittsdatum
BETWEEN '01.01.2010' AND '31.12.2020';
SELECT
name, vorname, gehalt, bonus
FROM mitarbeiter
WHERE
bonus=null;
Falsch: Vergleich (=) mit "unbekannt" liefert "weiß ich nicht"
SELECT
name, vorname, gehalt, bonus
FROM mitarbeiter
WHERE
bonus is null;
SELECT
name, vorname, gehalt, bonus
FROM mitarbeiter
WHERE
not bonus is null;
SELECT
name, gehalt, bonus,
gehalt + bonus AS gesamt
FROM mitarbeiter
WHERE oeid=17;
SELECT
name, gehalt, bonus,
gehalt +
CASE
WHEN bonus is null THEN 0
ELSE bonus
END AS gesamt
FROM mitarbeiter
WHERE oeid=17;
SELECT
name, oeid,
CASE
WHEN gehalt>100000 THEN 'hoch'
WHEN gehalt>35000 THEN 'mittel'
ELSE 'niedrig'
END AS gesamt
FROM mitarbeiter
ORDER BY gehalt;
SELECT mid, name
FROM MITARBEITER
ORDER BY mid
FETCH FIRST 3 ROWS ONLY;
SELECT * FROM dual;
SELECT id, name, Vorname
FROM t01
UNION
SELECT id, nachname as name, rufname as vorname
FROM t02;
SELECT name
FROM t01
UNION
SELECT nachname as name
FROM t02;
SELECT name
FROM t01
UNION ALL
SELECT nachname as name
FROM t02;
SELECT name
FROM t01
INTERSECT
SELECT nachname as name
FROM t02;
SELECT name
FROM t01
MINUS
SELECT nachname as name
FROM t02;
SELECT * FROM t10
where ende = to_date('2023/01/17', 'YYYY/MM/DD');
SELECT ende - beginn AS anzahl_tage FROM t10;
SELECT ende, ende + 2 FROM t10;
SELECT aufgabe || 'a' as a
FROM t10;
SELECT substr(aufgabe, 2, 3) as a
FROM t10;
SELECT length(aufgabe) as l
FROM t10;
SELECT to_char(123.4, '999D9') as wert FROM dual UNION ALL
SELECT to_char(123.4, '999D99') as wert FROM dual UNION ALL
SELECT to_char(123.4, '9999D99') as wert FROM dual UNION ALL
SELECT to_char(123.4, '0000D99') as wert FROM dual UNION ALL
SELECT to_char(123.4, '9G999G999D99') as wert FROM dual UNION ALL
SELECT to_char(1234567.89, '9G999G999D99') as wert FROM dual;
SELECT ...