summaryrefslogtreecommitdiff
path: root/ws2015/dbs/blaetter/07/abgabe.md
blob: 1b5297aab879fe79caca06a623ddafc3dc8c34c1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
---
header-includes:
  - \lstset{frame=single, breaklines=true, postbreak=\raisebox{0ex}[0ex][0ex]{\ensuremath{\color{red}\hookrightarrow\space}}}
---

# Anfragen in SQL

a)

~~~ {.sql}
SELECT pname FROM P WHERE ort IN (SELECT sitz FROM L WHERE lname = "Müller" OR lname = "Schmidt" )
~~~

b)

~~~ {.sql}
SELECT pname FROM P WHERE pnr IN (SELECT LTP.pnr FROM LTP, T WHERE T.tnr = LTP.tnr AND T.gewicht > 10)
~~~

c)

~~~ {.sql}
SELECT lname, status, sitz FROM L ORDER BY status, sitz DESC
~~~

d)

~~~ {.sql}
SELECT tname, farbe, gewicht FROM T WHERE gewicht >= (SELECT MAX(gewicht) FROM T)
~~~

e)

~~~ {.sql}
SELECT P.pname FROM P, LTP LEFT JOIN ( SELECT lnr, COUNT(*) ls FROM L WHERE status <= 30 ) L ON LTP.lnr = L.lnr WHERE LTP.pnr = P.pnr AND L.ls <= 2
~~~

# Anfragen in SQL

a)

~~~ {.sql}
SELECT L.lname FROM L WHERE (SELECT COUNT(*) FROM LTP, P WHERE p.ort = "Berlin" AND LTP.lnr = L.lnr GROUP BY P.pnr) >= (SELECT COUNT(*) FROM P WHERE P.ort = "Berlin")
~~~