SQL Petak Vezba Sa Casa
SQL Petak Vezba Sa Casa
SELECT AVG (rental_rate) FROM film WHERE film_id IN (SELECT film_id FROM film_actor WHERE
actor_id=3);
SELECT AVG (rental_rate) FROM film JOIN film_actor ON film.film_id = film_actor.film_id WHERE
film_actor.actor_id=3;
FROM film AS f
JOIN film_actor AS fa
ON f.film_id = fa.film_id
WHERE fa.actor_id=3;
--Pronadji korisnike koji jos nisu vratili film, a i dalje imaju aktivan status
JOIN rental AS r
ON c.customer_id=r.customer_id;
JOIN rental AS r
ON c.customer_id=r.customer_id;
JOIN rental AS r
ON c.customer_id=r.customer_id
JOIN address AS a
ON cs.address_id=a.address_id
JOIN city AS ct
ON a.city_id=ct.city_id
JOIN country AS c
ON ct.country_id=c.country_id
GROUP BY c.country;
JOIN address AS a
ON cs.address_id=a.address_id
JOIN city AS ct
ON a.city_id=ct.city_id
JOIN country AS c
ON ct.country_id=c.country_id
GROUP BY c.country;
SELECT c.country FROM customer AS cs
JOIN address AS a
ON cs.address_id=a.address_id
JOIN city AS ct
ON a.city_id=ct.city_id
JOIN country AS c
ON ct.country_id=c.country_id;
--GROUP BY c.country;
JOIN address AS a
ON cs.address_id=a.address_id
JOIN city AS ct
ON a.city_id=ct.city_id
JOIN country AS c
ON ct.country_id=c.country_id
GROUP BY c.country;
--rezultat koji dobijamo: ERROR: column "cs.last_name" must appear in the GROUP BY clause or be used
in an aggregate function
JOIN address AS a
ON cs.customer_id=a.address_id;
--spojene tabele, ali po kolonama koje medjusobno nemaju veze (izvodljivo, ali bez smisla)
--Prikazati sve filmove koji traju duže od 150 minuta i sortirati ih po dužini trajanja
JOIN city AS ct
ON c.country_id=ct.country_id
GROUP BY c.country;
JOIN city AS ct
ON c.country_id=ct.country_id
GROUP BY c.country;
JOIN address AS a
ON ct.city_id=a.city_id
JOIN store AS s
ON a.address_id=s.address_id
GROUP BY ct.city;
JOIN film_category AS fc
ON f.film_id=fc.film_id
JOIN category AS c
ON fc.category_id=c.category_id
GROUP BY c.name;
JOIN film_category AS fc
ON f.film_id=fc.film_id
JOIN category AS c
ON fc.category_id=c.category_id
GROUP BY c.name;
JOIN film_category AS fc
ON f.film_id=fc.film_id
JOIN category AS c
ON fc.category_id=c.category_id
GROUP BY c.name
ORDER BY c.name ASC;
--poredjano abecedno
JOIN language AS l
ON f.language_id=l.language_id