1.Retrieve film titles and their rental rates. Use column aliases to rename title as "Movie Title" and rental_rate as "Rate".
select title as "Movie Title" , rental_rate as "Rate" from film;
"As" is used in query to display the column aliases
2.List customer names and their email addresses. Alias first_name and last_name as "First Name" and "Last Name".
select first_name as "First Name" , last_name as "Last Name" , email from customer;
"As" is used in query to display the column aliases
3.Get a list of films sorted by rental rate in descending order. If two films have the same rental rate, sort them alphabetically by title.
select title,rental_rate from film order by rental_rate desc ,title asc ;
"Order by" used to display them in ascending and descending order
4.Retrieve actor names sorted by last name, then first name.
select first_name,last_name from actor order by last_name,first_name;
5.List all unique replacement costs from the film table.
select distinct(replacement_cost) from film;
"distinct" is used for unique display and remove duplicates
6.List all films' title and length in minutes. Alias length as "Duration (min)".
select title,length as "Duration (min)" from film;
7.Retrieve customer first and last names along with their active status. Alias active as "Is Active".
select first_name,last_name,active as lsActive from customer;
8.Retrieve the list of film categories sorted alphabetically.
select title from film order by title asc ;
9.List films by length, sorted in descending order. Include only the title and length.
select title,length from film order by length desc;
10.Retrieve all actor names, sorted by their first name in descending order.
select first_name from actor order by first_name desc;
11.List all unique ratings available in the film table.
select distinct rating from film;
12.Find all unique rental durations from the film table.
select distinct rental_duration from film;
13.Retrieve the first unique customer ID based on active status. Include the customer_id and active columns, and order by customer_id.
select distinct customer_id,active from customer where activebool= TRUE order by customer_id limit 1;
"where" is used to satisfy the condition
14.List the earliest rental date for each customer. Include customer_id and rental_date, and order by customer_id.
select customer_id,rental_date from rental order by rental_date desc,customer_id asc;
15.List the 10 shortest films by length. Include the title and length.
select title,length from film order by length asc limit 10;
16.Get the top 5 customers with the highest customer_id. Include the first and last name.
select customer_id,first_name,last_name from customer order by customer_id desc limit 5;
17.Retrieve all unique values of store_id from the inventory table.
select distinct store_id from inventory limit 10;
18.Find all unique replacement_cost values in the film table. Sort the results in ascending order.
select distinct replacement_cost from film order by replacement_cost asc ;
19.List the first rental date for each store. Include store_id and rental_date, and sort by store_id.
select store_id ,last_update from store order by last_update asc ,store_id asc limit 1;
20.Retrieve a list of film ratings sorted alphabetically and include only unique values.
select distinct rating from film order by rating asc;
21.List films by rating in ascending order and length in descending order.
select rating , length from film order by rating asc , length desc;
22.Retrieve actor names sorted by last_name in ascending order and first_name in descending order.
select last_name,first_name from actor order by last_name asc , first_name desc;
23.List films ordered by replacement_cost in ascending order and rental_rate in descending order.
select replacement_cost , rental_rate from film order by replacement_cost asc , rental_rate desc;
24.Retrieve customer names sorted by last_name ascending and first_name descending.
select last_name,first_name from customer order by last_name asc,first_name desc;
25.List all rentals sorted by customer_id ascending and rental_date descending
select customer_id,rental_date from rental order by customer_id asc,rental_date desc;.
26.Retrieve a list of films ordered by rental_duration ascending and title descending.
select title,rental_duration from film order by rental_duration asc,title desc;
Comments
Post a Comment