Five SQL queries explained
Not what you're looking for?
4.1) Consider the insurance database below, where the primary keys are underlines. Construct the following SQL queries for this relational database.
INSURANCE DATABASE
Person ( ss#, name, address)
Car (license, year, model)
Accident (data, driver, damage - amount)
Owns (ss#, license)
Log (license, date, driver)
I
a.) Find the total number of people whose cars were involved in accidents in 1989.
b.) Find the number of accidents in which the cars belonging to "John Smith" were involved.
c.) Add a new customer to the database.
d.) Delete the Mazda belonging to "John Smith".
e.) Add a new accident record for the Toyota belonging to "Jones".
Purchase this Solution
Solution Summary
This solution creates five SQL queries and explains how they work.
Solution Preview
This solution assumes that the "driver" in the Accident table is associated with the ssn in the Person table. This also uses generic SQL and doesn't rely on any database specific commands. One caveat here is that different databases handle date comparisons differently.
This solutions uses the most generic way of handling dates.
a.) Find the total number of people whose cars were involved in accidents in 1989.
SELECT count(*)
FROM Accident
WHERE (date >= 1/1/1989) AND (date <= 12/31/1989)
This query selects "count(*)" of all of the records in the Accident table where the date of the accident is in 1989.
b.) Find the number ...
Purchase this Solution
Free BrainMass Quizzes
Excel Introductory Quiz
This quiz tests your knowledge of basics of MS-Excel.
Word 2010: Table of Contents
Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.
Java loops
This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.
C# variables and classes
This quiz contains questions about C# classes and variables.
Basic Computer Terms
We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.