Question

In: Computer Science

Tables CUSTOMER CustomerID FirstName LastName Address Phone LicenseNo 1 David Hacker 101 Yammba road, Rockhampton 0749008877...

Tables

CUSTOMER

CustomerID

FirstName

LastName

Address

Phone

LicenseNo

1

David

Hacker

101 Yammba road, Rockhampton

0749008877

089 777 123

2

Tony

Morrison

98 South street, Melbourne

0490787772

088777555

3

Issac

Newton

90 Heaven road, Sydney

0299001122

099 776 123

4

James

Farrell

101 St Lucia Garden, Brisbane

0733099000

090 566 777

5

David

Land

345 Illinois road, Brisbane

0739000554

456 000 999

6

Peter

Garry

201 South port road, Gold Coast

0745676766

234 090 767

RENTAL

RentalID

CustomerID

RegoNo

StartDate

EndDate

Cost

1

4

NAK455

1/07/2019

3/07/2019

$105.00

2

4

QWA321

5/07/2019

7/07/2019

$180.00

3

1

QWA321

2/06/2019

5/06/2019

$240.00

4

2

LLP677

15/06/2019

21/06/2019

$280.00

5

3

SUN909

15/07/2019

18/07/2019

$140.00

6

3

NAK455

2/08/2019

5/08/2019

$140.00

CAR

RegoNo

MakeAndModel

NumOfSeats

ManufacturedYear

CategoryID

ABC455

Toyota Camry

5

1

LLP677

Toyota Hilux

4

2

NAK455

Toyota Corolla

4

2017

1

PAK561

Nissan Navara

5

2017

3

QWA321

VW Caravelle

9

2017

3

SOU320

GM Cardillac

7

2011

4

SUN909

VW Passat

5

2000

1

QLD101

Volvo XC60

5

2017

5

VEHICLE_CATEGORY

CategoryID

CategoryName

DailyHireRate

1

sedan

$35.00

2

ute

$40.00

3

minivan

$60.00

4

limos

$450.00

5

suv

$55.00

Note that:

  • You are asked to provide a general solution to each request. If the database contents change, each of your queries should continue to answer the information requested correctly.
  • Simple queries are preferred; if your queries are unnecessarily complex you may lose marks.
  • For the given sample data, your queries should be able to generate the same data and column names as shown in the result table for each request.
  • You are not required to sort the results in any order unless requested.
  • State any assumption that you make to clarify your understanding of the information request.

Provide appropriate queries for the following requirements

List the details of cars that are Toyota sedan. The details include registration number, make and model, the number of seats, manufactured year, category ID, and category name.

<SQL_QUERY>

Which cars have never been rented out? List the details that include the car’s registration number, make and model, number of seats, manufactured year, category as well as the daily hire rate.

<SQL_QUERY>

Which cars have been rented out more than once? Show the car’s

registration number, make and model, manufactured year, and the number of rentals.

<SQL_QUERY>

Find out the rental activities that have the most expensive cost. This includes the customer names, car registration numbers, make and models, the start hire dates, end hire dates and the costs. Note: You will need to use an aggregate function.        

<SQL_QUERY>

How many times of rental activity were from each customer? Show the customer name, phone, and the number of rentals. Order the list so that the customers who rented the most appear first.

<SQL_QUERY>

Solutions

Expert Solution

Here are the SQL queries:

-- List the details of cars that are Toyota sedan. The details include registration number, make and model, the number of seats, manufactured year, category ID, and category name.

select RegoNo, MakeAndModel, NumOfSeats, ManufacturedYear, c.CategoryId, v.CategoryName
        from CAR c inner join VEHICLE_CATEGORY v ON c.CategoryID = v.CategoryID
        WHERE MakeAndModel LIKE "Toyota%"
        
-- Which cars have never been rented out? List the details that include the car’s registration number, make and model, number of seats, manufactured year, category as well as the daily hire rate.
select RegoNo, MakeAndModel, NumOfSeats, ManufacturedYear, v.CategoryName, v.DailyHireRate
        from CAR c inner join VEHICLE_CATEGORY v ON c.CategoryID = v.CategoryID
        WHERE RegoNo not in (select RegoNo from RENTAL)
        
-- Which cars have been rented out more than once? Show the car’s
registration number, make and model, manufactured year, and the number of rentals.
select c.RegoNo, MakeAndModel, ManufacturedYear, count(*) as NoRentals
        from CAR c inner join RENTAL r on c.RegoNo = r.RegoNo
        GROUP BY RegoNo
        HAVING count (*) > 1
        
-- Find out the rental activities that have the most expensive cost. This includes the customer names, car registration numbers, make and models, the start hire dates, end hire dates and the costs. Note: You will need to use an aggregate function.  
select FirstName + " " + LastName as CustomerName, c.RegoNo, MakeAndModel, StartDate, EndDate, Cost
        from CAR c inner join RENTAL r on c.RegoNo = r.RegoNo
                INNER JOIN CUSTOMER u ON u.CustomerID = r.CustomerID
                WHERE Cost = (select MAX(cost) from RENTAL)
                
-- How many times of rental activity were from each customer? Show the customer name, phone, and the number of rentals. Order the list so that the customers who rented the most appear first.
select FirstName + " " + LastName as CustomerName, Phone, COUNT(*) as NoRentals
        from Customer c INNER JOIN RENTAL r ON c.CustomerID = r.CustomerID
        GROUP BY CustomerID

In case of any doubts or questions, please ask via Comments.


Related Solutions

A person has a firstname, lastname, ID, and email. A phone number is of the form...
A person has a firstname, lastname, ID, and email. A phone number is of the form countrycode, number. A person may have several related telephone numbers, and a telephone number may be associated with multiple people. The possible relationships are: home, work, and mobile. A person may have at most one phone number for each type of relationship. Draw schema diagram and define and create the tables that implement the model and enforce the given constraints.
Design a database/mysql that has 3 tables: TABLE 1 student: StudID (int), LastName (varchar), FirstName (varchar),...
Design a database/mysql that has 3 tables: TABLE 1 student: StudID (int), LastName (varchar), FirstName (varchar), MiddleName(varchar) TABLE 2 Course: StudID, CourseID TABLE 3 study course: CourseID(int), CourseTitle(varchar), Units(int), PreqCourse(varchar) ** Insert at least 5 records. ** Use the "select" command to view the content of the tables. ** POST THE SCREENSHOT
Problem: Read the following tables and answer the following questions: Customers Customer ID Name Address Phone...
Problem: Read the following tables and answer the following questions: Customers Customer ID Name Address Phone Email 9087 John Doe 204 University Ave. 987-098-9087 [email protected] 2098 Bill Lawrence 123 Jones St 717-387-3387 Business 2398 Laura Smith 0900 West Blvd. 901-234-4567 Information Transactions Customer ID Account Number Date of Last Transaction 9087 375 01/31/98 2098 123 03/09/97 2398 375 09/21/97 2098 375 12/31/97 2398 123 02/01/98 Accounts Account Number Balance Account Type 375 234.45 Checking 123 056.90 Savings 1. Who owns...
describe what these mysql queries do 1.) select lastname, firstname, region, birthday from Members where birthday...
describe what these mysql queries do 1.) select lastname, firstname, region, birthday from Members where birthday in (select birthday from Members where email is not null) 2.) select Sales.Firstname As EmpFirst, Sales.Lastname as EmpLast, Sup.Firstname as SupFirst, Sup.Lastname as SupLast from Salespeople Sales inner join Salespeople Sup On Sales.Supervisor=Sup.SalesID 3.) select Region, Gender, Count(*) As Num from Members where Email is null group by region, gender 4.) select title from titles where not Genre = 'Jazz';
Write the correct code in SQL 1. What is the name and address of the customer...
Write the correct code in SQL 1. What is the name and address of the customer that placed order 57? 2. Assume there is only one product with the description Cherry End Table. List the names of the raw materials that go into making that product. 3. List the product id, description, and finish of the least expensive products. (Note: A couple of rows show a price of 0. Exclude products with a price of 0 from your query.) 4....
QUESTION 1 For the salesdb tables loaded in your environment, the table specifications are below: CUSTOMER...
QUESTION 1 For the salesdb tables loaded in your environment, the table specifications are below: CUSTOMER (custno, lname, fname, mname, email, mobile, addrln1, addrln2, addrln3, city, state, zip, status) PRODUCT (prodno, sku, unit, long_desc, short_desc, unitprice, qty_on_hand, qty_on_order) SALES (salesno, saledate, custno, prodno, salesqty, unitprice, lineamount, taxable, taxrate, discountrate) Write SQL that will list the sales to custno=11, Eva Santis. The resultset should include: custno, fname, lname, salesno, prodno, long_desc, product unitprice, salesqty, totalcost for each line item. Test your...
1) If a customer provides us an email address, does this automatically mean that we have...
1) If a customer provides us an email address, does this automatically mean that we have the right to use it in our marketing materials? Why or why not? What can we do to help alleviate any misunderstandings that may occur if we misread our customers intent when the customer gave us their email address? 2) What information other than the basic customer contact information like name and address do you believe is the most important to collect for marketing...
SUPPLIERS(SupplierID, SupplierName, ContactName, Address, City, PostalCode, Country, Phone) CUSTOMERS(CustomerID, CustomerName, ContactName, Address, City, PostalCode, Country) 1.Show...
SUPPLIERS(SupplierID, SupplierName, ContactName, Address, City, PostalCode, Country, Phone) CUSTOMERS(CustomerID, CustomerName, ContactName, Address, City, PostalCode, Country) 1.Show suppliers that do not have a PO Box but only show those whose name starts with a G or an N 2.Show suppliers that are located in countries from A to G and cities from N to Z LastName: I got # records in the output (result set). 3.Show the set of city and country combinations (listing each combination only once) where our customers...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT