- 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.
- 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.
- 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.
- 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.
- Unique replacement costs
SELECT DISTINCT replacement_cost
FROM film;
Explanation:
Used DISTINCT to remove duplicate replacement costs.
- Film title and length
SELECT title, length AS "Duration (min)"
FROM film;
Explanation:
Selected film title and renamed length column.
- Customer active status
SELECT first_name, last_name, active AS "Is Active"
FROM customer;
Explanation:
Displayed customer names and their active status.
- Film categories sorted
SELECT name
FROM category
ORDER BY name;
Explanation:
Listed categories and sorted alphabetically.
- Films by length
SELECT title, length
FROM film
ORDER BY length DESC;
Explanation:
Sorted films based on length in descending order.
- Actor names descending
SELECT first_name, last_name
FROM actor
ORDER BY first_name DESC;
Explanation:
Sorted actors by first name in descending.
- Unique ratings
SELECT DISTINCT rating
FROM film;
Explanation:
Displayed only unique ratings.
- Unique rental duration
SELECT DISTINCT rental_duration
FROM film;
Explanation:
Got unique rental durations.
- 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.
- 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.
- 10 shortest films
SELECT title, length
FROM film
ORDER BY length
LIMIT 10;
Explanation:
Sorted by length and picked first 10.
- 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.
- Unique store ids
SELECT DISTINCT store_id
FROM inventory;
Explanation:
Got unique store ids.
- Replacement cost sorted
SELECT DISTINCT replacement_cost
FROM film
ORDER BY replacement_cost;
Explanation:
Unique values and sorted in ascending order.
- 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.
- Unique ratings sorted
SELECT DISTINCT rating
FROM film
ORDER BY rating;
Explanation:
Displayed unique ratings in sorted order.
- Films by rating and length
SELECT *
FROM film
ORDER BY rating, length DESC;
Explanation:
Sorted by rating first, then by length descending.
- 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.
- Films by cost and rate
SELECT *
FROM film
ORDER BY replacement_cost ASC, rental_rate DESC;
Explanation:
Sorted by replacement cost, then rental rate.
- 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.
- Rentals sorting
SELECT *
FROM rental
ORDER BY customer_id ASC, rental_date DESC;
Explanation:
Sorted rentals by customer and latest date.
- 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)