Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write SQL queries that answer the following questions. Make sure you compose a query that does not use literal values determined by perusing the tuples.

Write SQL queries that answer the following questions. Make sure you compose a query that does not use literal values determined by perusing the tuples. Also, remember some queries may generate an empty result.
1. For each shark (found in the shark table), determine the number of detections for the shark as documented within the database. Each tuple in the result should contain the sharks name, sharks id and the number of detections. In the result, rename the number of detections to sightings.
2. Determine the number of shark detections for each bay (as documented in the database). Each tuple in the result should contain the bays name and the number of detections. Sort the result by the number of detections in descending order.
3. What receiver has been documented as having the most number of shark detections? The result should contain the receivers area, town, state, and the number of detections. There is one receiver that has the maximum value.
4. Make a separate table from the receiver table where the records are for the bayside receivers. Name the new table bayside_encounters. Remember, a table can only be created once. If you attempt to create the same table multiple times it will generate an error.
5. Which sharks have been documented as part of an attack. The result should contain the shark.id, shark.name, sex, length and number of detections.
6. For each bay (each name in the bay table), create an aggregated field that contains a list of the receivers in that bay (represented by the field area). The result set should contain the bay name and the grouped area name for the receivers. Do not duplicate area names within the grouped list of receivers.
7. Which is the largest shark (by length)? Return the sharks name in the result.
8. How many shark sightings have occurred for the different towns in the database? The result should contain the town name, state and shark detections.
9. Find all female sharks that are less than 8 feet. Return all fields from the shark table and order the results by length in ascending order..
10. For each sponsor in the sponsor table, determine the number of receivers they sponsor. The result should contain the sponsor name and the count. Make sure all sponsors appear in the result. If a sponsor does not appear in the receiver table, then the count for the number of receivers should be 0.
11. Determine the total number of shark detections associated with their sponsored receivers. If a receiver is not sponsored the detections should still be aggregated and assigned to the NULL sponsor. The result should contain the sponsor name and the number of detections.
12. For each attack, report the shark name, if the attack was fatal, the description of the attack,the date of the attack, the victims activity when attacked , the town where the attacked occurred, the state, the victims name, the victims age,
13. Determine the town that first deployed a receiver. The result should contain the town, the state and the date of deployment for the receiver.
14. How many receivers are deployed for each town? The result should contain the town name, the town state, and the number of receivers (renamed to num_receivers). All towns in the township table should appear in the result. If a town has no receivers, then the count num_receivers should be 0.
15. Find the towns that do not have a receiver and not have an attack. Return the town name and the state of all towns not found in either the receiver table or the attack table.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is Working Capital ? Explain its types.

Answered: 1 week ago