Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In SQL, running on an Oracle database, write a query for each problem that solve

ID: 3587670 • Letter: I

Question

In SQL, running on an Oracle database, write a query for each problem that solves the task. Please ensure that it

1) Find for each person how many cars manufactured by Honda or Toyota they own. If a person does not own any such cars, she should still appear in the result with the number of cars reported as 0. Write your query using outer join. Be very careful not to count also the BMW cars a person owns.

2) Write the same query as above, but using a scalar query for counting the Hondas and Toyotas a person owns, without outer join.

Note: The queries listed above should yield the following result shown below. If possible, try to show the output for your queries.

NAME Jenson Button1 Rubens Barrichello 1 Sebastian Vettel 0 Mark Webber Lewis Hamilton 2 Felipe Massa 0 NUM_OF_CARS CD

Explanation / Answer

1)

select Name, count(License) from Person p outer join (select License from the Car where Model='Honda' OR Model='Toyota') Car c outer join (select License from Car c,Owns o where c.License=o.License) Owns on p.Driverid=o.DriverId and o.License=c.License.

2) select count(License) from Car c,Owns o,Person p where p.License=c.License and p.Driverid=o.driverid where c.Model='Honda' or c.Model='Toyota';

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote