Books Table
Books Table
You are tasked with writing SQL queries to extract information from an online bookstore database. The database
contains three tables: Books, Authors, and Orders. Below are the structures of these tables:
BOOKS TABLE:
AUTHORS TABLE:
ORDERS TABLE:
1. Write a SQL query to retrieve the names of all authors who were born before the year 1985.
2. Write a SQL query to calculate the total revenue generated by the bookstore from book sales. (Hint: Use the
SUM function)
3. Write a SQL query to find the title and publication year of the top 2 most expensive books.
4. Write a SQL query to count the number of orders placed in each year and order them by the year in
ascending order.
5. Write a SQL query to find the author who has the highest average book price, along with their average book
price.
Exercise: Online Store Database Queries
In this exercise, you will work with a simplified database schema for an online store. The schema includes three
tables: `Customers`, `Products`, and `Orders`. You will write SQL queries to retrieve specific information from these
tables.
Schema:
- `Customers` table:
- `first_name` (text)
- `last_name` (text)
- `email` (text)
- `Products` table:
- `product_name` (text)
- `price` (decimal)
- `Orders` table:
- `order_date` (date)
- `quantity` (integer)
**Tasks:**
1. Write an SQL query to retrieve the first and last names of all customers.
2. Write an SQL query to retrieve the product names and their prices.
3. Write an SQL query to retrieve the total quantity of products sold for each order.
4. Write an SQL query to retrieve the first name, last name, and total amount spent by each customer.
5. Write an SQL query to retrieve the product name, price, and the number of times each product has been ordered.
6. Write an SQL query to retrieve the customer's first name, last name, and the total price of all products they have
ordered.