Forem

Abinaya Dhanraj
Abinaya Dhanraj

Posted on

CA - 22

  1. Film titles and rental rates

SELECT title AS "Movie Title", rental_rate AS "Rate"
FROM film;

Explanation:
Here I am selecting title and rental rate from film table.
I used AS to rename the column names for better understanding.

  1. Customer names and email

SELECT first_name AS "First Name", last_name AS "Last Name", email
FROM customer;

Explanation:
I selected customer name and email.
Used alias to display column names properly.

  1. Films sorted by rental rate

SELECT *
FROM film
ORDER BY rental_rate DESC, title ASC;

Explanation:
First sorted by rental rate in descending.
If same rate, then sorted by title alphabetically.

  1. Actor names sorted

SELECT first_name, last_name
FROM actor
ORDER BY last_name, first_name;

Explanation:
Sorted actors by last name first, then first name.

  1. Unique replacement costs

SELECT DISTINCT replacement_cost
FROM film;

Explanation:
Used DISTINCT to remove duplicate replacement costs.

  1. Film title and length

SELECT title, length AS "Duration (min)"
FROM film;

Explanation:
Selected film title and renamed length column.

  1. Customer active status

SELECT first_name, last_name, active AS "Is Active"
FROM customer;

Explanation:
Displayed customer names and their active status.

  1. Film categories sorted

SELECT name
FROM category
ORDER BY name;

Explanation:
Listed categories and sorted alphabetically.

  1. Films by length

SELECT title, length
FROM film
ORDER BY length DESC;

Explanation:
Sorted films based on length in descending order.

  1. Actor names descending

SELECT first_name, last_name
FROM actor
ORDER BY first_name DESC;

Explanation:
Sorted actors by first name in descending.

  1. Unique ratings

SELECT DISTINCT rating
FROM film;

Explanation:
Displayed only unique ratings.

  1. Unique rental duration

SELECT DISTINCT rental_duration
FROM film;

Explanation:
Got unique rental durations.

  1. Unique customer by active

SELECT DISTINCT customer_id, active
FROM customer
ORDER BY customer_id
LIMIT 1;

Explanation:
Selected unique customer id and sorted.
Used LIMIT 1 to get first record.

  1. Earliest rental date per customer

SELECT customer_id, MIN(rental_date) AS rental_date
FROM rental
GROUP BY customer_id
ORDER BY customer_id;

Explanation:
Used MIN() to get earliest rental date for each customer.

  1. 10 shortest films

SELECT title, length
FROM film
ORDER BY length
LIMIT 10;

Explanation:
Sorted by length and picked first 10.

  1. Top 5 customers

SELECT first_name, last_name
FROM customer
ORDER BY customer_id DESC
LIMIT 5;

Explanation:
Sorted by highest customer id and got top 5.

  1. Unique store ids

SELECT DISTINCT store_id
FROM inventory;

Explanation:
Got unique store ids.

  1. Replacement cost sorted

SELECT DISTINCT replacement_cost
FROM film
ORDER BY replacement_cost;

Explanation:
Unique values and sorted in ascending order.

  1. First rental per store

SELECT store_id, MIN(rental_date) AS rental_date
FROM rental
GROUP BY store_id
ORDER BY store_id;

Explanation:
Got first rental date for each store.

  1. Unique ratings sorted

SELECT DISTINCT rating
FROM film
ORDER BY rating;

Explanation:
Displayed unique ratings in sorted order.

  1. Films by rating and length

SELECT *
FROM film
ORDER BY rating, length DESC;

Explanation:
Sorted by rating first, then by length descending.

  1. Actor sorting mixed

SELECT first_name, last_name
FROM actor
ORDER BY last_name ASC, first_name DESC;

Explanation:
Sorted last name ascending and first name descending.

  1. Films by cost and rate

SELECT *
FROM film
ORDER BY replacement_cost ASC, rental_rate DESC;

Explanation:
Sorted by replacement cost, then rental rate.

  1. Customer sorting

SELECT first_name, last_name
FROM customer
ORDER BY last_name ASC, first_name DESC;

Explanation:
Sorted customers based on last and first name.

  1. Rentals sorting

SELECT *
FROM rental
ORDER BY customer_id ASC, rental_date DESC;

Explanation:
Sorted rentals by customer and latest date.

  1. Films by duration and title

SELECT *
FROM film
ORDER BY rental_duration ASC, title DESC;

Explanation:
Sorted by rental duration and then title.

Top comments (0)