SELECT stolpci
FROM tabela [NATURAL] [LEFT | RIGHT | FULL] JOIN tabela2
[ON pogoj | USING (stolpec1, stolpec2)]
WHERE pogoj
GROUP BY stolpci
HAVING pogoj
ORDER BY stolpci
LIMIT število
Vrnite naslove filmov in imena glavnih igralcev. Rezultate uredite po imenu igralca in nato še po naslovu filma.
SELECT naslov, ime FROM film
JOIN vloga ON film.id = vloga.film
JOIN oseba ON vloga.oseba = oseba.id
WHERE tip = 'I' AND mesto = 1
ORDER BY ime, naslov;
Za vsakega režiserja (izpišite ga z IDjem in imenom) izpišite skupno dolžino filmov, ki jih je režiral (brez igranja). Rezultate uredite po imenu režiserja.
SELECT oseba.id, ime, SUM(dolzina) FROM film
JOIN vloga ON film.id = vloga.film
JOIN oseba ON vloga.oseba = oseba.id
WHERE tip = 'R'
GROUP BY oseba.id, ime
ORDER BY ime;
Za vsak žanr (izpišite ga z imenom) izpišite število različnih igralcev in število različnih režiserjev, ki so sodelovali pri filmih tega žanra. Rezultate uredite padajoče po vsoti števila igralcev in števila režiserjev (če se nekdo pojavi tako kot igralec kot režiser, se tukaj šteje dvakrat).
SELECT naziv,
COUNT(DISTINCT igralec.oseba) AS stevilo_igralcev,
COUNT(DISTINCT reziser.oseba) AS stevilo_reziserjev FROM film
JOIN pripada ON film.id = pripada.film
JOIN zanr ON pripada.zanr = zanr.id
JOIN vloga AS igralec ON film.id = igralec.film
JOIN vloga AS reziser ON film.id = reziser.film
WHERE igralec.tip = 'I' AND reziser.tip = 'R'
GROUP BY zanr.id, naziv
ORDER BY stevilo_igralcev + stevilo_reziserjev DESC;
SELECT naziv,
(SELECT COUNT(DISTINCT oseba) FROM film
JOIN vloga ON film.id = vloga.film
JOIN pripada ON film.id = pripada.film
WHERE tip = 'I' AND zanr = zanr.id) AS stevilo_igralcev,
(SELECT COUNT(DISTINCT oseba) FROM film
JOIN vloga ON film.id = vloga.film
JOIN pripada ON film.id = pripada.film
WHERE tip = 'R' AND zanr = zanr.id) AS stevilo_reziserjev
FROM zanr
ORDER BY stevilo_igralcev + stevilo_reziserjev DESC;
JOIN
operationNaloga | TA | ŽA | AB | PK | KK | AL | JL | HL | MM | AO | DR | BR | AS | MS | DŠ | LT | TT |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
2 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
3 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
4 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
5 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
6 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
7 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
8 | x | x | x | x | x | x | x | x | x | x | x | x | x | ||||
9 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
11 | x | x | x | x | x | x | x | x | x | x | x | x | x | x | |||
12 | x | x | x | x | x | x | x | x | x | x | x | x | x | ||||
13 | x | x |
JOIN
operationsNaloga | TA | ŽA | AB | PK | KK | AL | JL | HL | MM | AO | DR | BR | AS | MS | DŠ | LT | TT |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | x | x | x | x | x | x | x | x | x | x | x | x | x | ||||
2 | x | x | x | x | x | x | x | x | x | x | x | x | x | ||||
3 | x | x | x | x | x | x | x | x | x | x | x | x | x | ||||
4 | x | x | x | x | x | x | x | x | x | x | x | x | x | ||||
5 | x | x | x | x | x | x | x | x | x | x | x | x | |||||
6 | x | x | x | x | x | x | x | x | x | x | x | ||||||
7 | x | x | x | x | x | x | x | x | x | ||||||||
8 | x | x | x | x | x | x | x | x | |||||||||
9 | x | x | x | x | x | x | x | x | |||||||||
11 | x | x | x | x | x | x | x | ||||||||||
12 | x | x | x | x | x | x | |||||||||||
13 | x | x | x | x | x | x | |||||||||||
14 | x | x | x | x | x | x | |||||||||||
15 | x | x | x | x | x |