Folgende Beispiele beziehen sich auf die Universitätsdatenbank, wobei die Relationen Professoren, Assistenten und Studenten jeweils um ein Attribut GebDatum vom Typ Datetime 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
select * from Studenten where Semester >= 1 and Semester <= 4alternativ
select * from Studenten where Semester between 1 and 4alternativ
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 Name, Datename(Day, Gebdatum) as Tag, Datename(Month, GebDatum) as Monat, Datename(Year, GebDatum) as Jahr from studenten
select Name, datediff(year,GebDatum, getdate()) as Jahre from studenten
select Name, datename(weekday,GebDatum) as Wochentag from studenten
select Name, datename(month,GebDatum) as Wochentag from studenten
select Name, Titel from Professoren, Vorlesungen where PersNr = gelesenVon and Titel = 'Logik'
select Name, Titel from Studenten, hoeren, Vorlesungen where Studenten.MatrNr = hoeren.MatrNr and hoeren.VorlNr = Vorlesungen.VorlNralternativ:
select s.Name, v.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) as Ältester from Professoren group by Rang
select gelesenVon as PersNr, sum(SWS) as Lehrbelastung from Vorlesungen group by gelesenVon
select gelesenVon as PersNr, sum(SWS) as Lehrbelastung from Vorlesungen group by gelesenVon having avg(SWS) > 3alternativ unter Verwendung von Gleichkommadurchschnitt:
select gelesenVon as PersNr, sum (SWS) as Lehrbelastung from Vorlesungen group by gelesenVon having avg(cast(SWS as float)) > 3.0
select Name, sum(SWS) from Vorlesungen, Professoren where gelesenVon = PersNr and Rang='C4' group by gelesenVon, Name having avg(cast(SWS as float)) > 3.0
select * from pruefen where Note = (select min(Note) from pruefen)
select PersNr, Name, (select sum(SWS) as Lehrbelastung from Vorlesungen where gelesenVon = PersNr) as Lehrbelastung from Professoren
select s.* from Studenten s where exists (select p.* from Professoren p where p.GebDatum > s.GebDatum)Alternativ:
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, min(GebDatum) as maximum from Professoren group by Rang) tmp where p.Rang = tmp.Rang and p.GebDatum = tmp.maximum
select h.VorlNr, h.AnzProVorl, g.GesamtAnz, cast(h.AnzProVorl as float)/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)
select Name from Professoren where PersNr not in ( select gelesenVon from Vorlesungen )Alternativ:
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 s.name, v.titel from studenten s join hoeren h on (s.matrnr=h.matrnr) join vorlesungen v on (h.vorlnr = v.vorlnr)
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' ) )