Jumat, 17 Februari 2012

Tugas Aplied Database II

1. Menampilkan tabel 3 customer yang paling sering melakukan rental
Asumsi kita sudah mempunyai database yang diberi nama sakila yang didalamnya terdapat beberapa tabel. Nah cara untuk menampilkannya yaitu :


SQL :

SELECT TOP 3 rental.customer_id, COUNT(rental.rental_id) AS JumlahPelanggan
FROM (category INNER JOIN film_category ON category.category_id = film_category.category_id) INNER JOIN ((film INNER JOIN inventory ON film.film_id = inventory.film_id) INNER JOIN rental ON inventory.inventory_id = rental.inventory_id) ON film_category.film_id = film.film_id group by rental.customer_id order by COUNT(rental.rental_id) desc ;

Output : 

2. Menampilkan tabel 3 film yang paling sering dipinjam

SQL :
SELECT TOP 3 film.title, count(rental.rental_id) AS JumlahTransaksi
FROM (category INNER JOIN film_category ON category.category_id = film_category.category_id) INNER JOIN ((film INNER JOIN inventory ON film.film_id = inventory.film_id) INNER JOIN rental ON inventory.inventory_id = rental.inventory_id) ON film_category.film_id = film.film_id
GROUP BY film.title
ORDER BY count(rental.rental_id) DESC;

Output :

Tidak ada komentar:

Posting Komentar