Folgende Beispiele beziehen sich auf die Universitätsdatenbank, wobei die Relationen Professoren, Assistenten und Studenten jeweils um ein Attribut GebDatum vom Typ Date erweitert worden sind.
select * from Studenten;
select PersNr, Name from Professoren where Rang = 'C4';
select count(*) from Studenten;
select Name, Semester/2 AS Studienjahr from Studenten where Semester is not null;
Alternativ:select * from Studenten where Semester >= 1 and Semester <= 4;
Alternativ:select * from Studenten where Semester between 1 and 4;
select * from Studenten where Semester in (1,2,3,4);
select * from Vorlesungen where upper(Titel) like '%ETHIK%';
select PersNr, Name, Rang from Professoren order by Rang desc, Name asc;
select distinct Rang from Professoren;
select to_char(GebDatum,'month DD, YYYY') AS Geburtstag from studenten;
select (sysdate - GebDatum) / 365 as Alter_in_Jahren from studenten;
select to_char(GebDatum,'day') from studenten;
select to_char(GebDatum,'hh:mi:ss') from studenten;
select Name, Titel from Professoren, Vorlesungen where PersNr = gelesenVon and Titel = 'Logik';
Alternativ:select Name, Titel from Studenten, hoeren, Vorlesungen where Studenten.MatrNr = hoeren.MatrNr and hoeren.VorlNr = Vorlesungen.VorlNr;
select s.Name, s.Titel from Studenten s, hoeren h, Vorlesungen v where s.MatrNr = h.MatrNr and h.VorlNr = v.VorlNr;
select a2.Name from assistenten a1, assistenten a2 where a2.boss = a1.boss and a1.name = 'Aristoteles' and a2.name != 'Aristoteles';
select avg(Semester) from Studenten;
select rang, max(GebDatum) from Professoren group by rang;
select gelesenVon, sum(SWS) from Vorlesungen group by gelesenVon;
select gelesenVon, sum(SWS) from Vorlesungen group by gelesenVon having avg(SWS) > 3;
select gelesenVon, Name, sum(SWS) from Vorlesungen, Professoren where gelesenVon = PersNr and Rang = 'C4' group by gelesenVon, Name having avg(SWS) > 3;
select * from pruefen where Note = (select avg(Note) from pruefen);
select PersNr, Name, (select sum(SWS) as Lehrbelastung from Vorlesungen where gelesenVon = PersNr) from Professoren;
Alternativ:select s.* from Studenten s where exists (select p.* from Professoren p where p.GebDatum > s.GebDatum);
select s.* from Studenten s where s.GebDatum < (select max(p.GebDatum) from Professoren p );
select a.* from Assistenten a, Professoren p where a.Boss = p.PersNr and p.GebDatum > a.GebDatum;
select tmp.MatrNr, tmp.Name, tmp.VorlAnzahl from (select s.MatrNr, s.Name, count(*) as VorlAnzahl from Studenten s, hoeren h where s.MatrNr = h.MatrNr group by s.MatrNr, s.Name) tmp where tmp.VorlAnzahl > 2;
select p.Rang, p.Name, tmp.maximum from Professoren p, (select Rang, max(GebDatum) as maximum from Professoren group by Rang) tmp where p.Rang = tmp.Rang and p.GebDat = tmp.maximum;
select h.VorlNr, h.AnzProVorl, g.GesamtAnz, h.AnzProVorl/g.GesamtAnz as Marktanteil from (select VorlNr, count(*) as AnzProVorl from hoeren group by VorlNr) h, (select count(*) as GesamtAnz from Studenten) g;
( select Name from Assistenten ) union ( select Name from Professoren );
( select Name from Assistenten ) minus ( select Name from Professoren );
( select Name from Assistenten ) intersect ( select Name from Professoren );
Alternativ:select Name from Professoren where PersNr not in ( select gelesenVon from Vorlesungen );
select Name from Professoren where not exists ( select * from Vorlesungen where gelesenVon = PersNr );
select Name from Studenten where Semester >= all ( select Semester from Studenten );
select Name from Studenten where Semester < some ( select Semester from Studenten );
select s.* from Studenten s where not exists (select * from Vorlesungen v where v.SWS = 4 and not exists (select * from hoeren h where h.VorlNr = v.VorlNr and h.MatrNr = s.MatrNr ) );
select * from Studenten natural join hoeren;
select Titel from Vorlesungen where VorlNr in ( select Vorgaenger from voraussetzen connect by Nachfolger = prior Vorgaenger start with Nachfolger = ( select VorlNr from Vorlesungen where Titel = 'Der Wiener Kreis' ) );