Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need to write an SQL for the following: Lastly, you are asked to find out if there are a larger number of players suffering injuries

Need to write an SQL for the following:

Lastly, you are asked to find out if there are a larger number of players suffering injuries based on weight? The researchers would like you to identify or count the number of injuries in three weight classes: a) 0-199 pounds, b) 200-299 pounds, and c) 300 or more pounds. First off, identify the attributes that will need to be displayed, knowing that you will need to select the count of injuries as well. Type the appropriate language into line 1. Label the injury column: Num. Injuries

Recall that you must use single quotations around any name or alias with a space between the words so that SQL knows it is one value. IMPORTANT: Put a comma after the last single quotation.

Next, you will use the CASE clause. CASE lets you evaluate conditions and return a value when the condition is met. For example, when some condition is met then do something. This is similar to if-then statements. Here youre going to set three conditions (the weight classes). When the weight of a player is 300 pounds or more, then you will create a class called 300+. When the weight of a player is between 199 pounds and 300 pounds, you will create a class called 200-299. Lastly when the weight of a player is less than 200 pounds, then you will create a class called 0-199.

In line 2, after your SELECT statement which is in line 1, type CASE. This is an indicator that conditions and results are to follow. In line 3, you will use the WHEN clause which stipulates that the following condition must be met in order for the THEN result to occur. After typing WHEN, specify that the weight must be greater than or equal to 300, then type THEN 300+. Line 3 should look like this:

WHEN weight>= 300 THEN 300+

Use this WHEN/THEN clause combination to set up the other two weight classes in lines 4 and 5. In line 6, you will need to end the case. This is also a good place to name the column where the weight classes will appear. Type END AS Weightclass

Weightclass is now a new attribute set by the CASE statement. It is ultimately going to be another column and therefore it is part of the SELECT clause which is why there has to be a comma after the last field or attribute in the SELECT line.

Now similar to Q3bUniqueConcussionsNames, the weights are in the player table and the injuries are in the injury table. So you will need to enter the FROM and JOIN clauses in lines 7 and 8.

Execute the query. You should have received an error. It is not implicit that by creating classes, that the result-set will be grouped by those weight classes. Use the GROUP BY clause in line 9 to group by the weight classes that you just created. Remember the GROUP BY statement should read:

GROUP BY attributename

Execute the query again. It should have worked this time, however notice that the weight classes appear in an ascending order (smallest to largest). Use the ORDER BY clause in line 10 to have the result-set appear in a descending order. Line 10 should look like this:

ORDER BY Weightclass desc

Execute the query. How many total injuries appear in this result-set?

In a new excel worksheet, type the number of results (or records) returned from this query into cell A1. In cell A3, paste the SQL query code. Use the CSV button in Sqlectron to copy the result-set, leave one row blank, and then paste the result-set. Label this worksheet Q5InjuryCountWeights. Save your excel document.

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

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

Question Can any type of stock or securities be used in an ESOP?

Answered: 1 week ago

Question

Question Can a self-employed person adopt a money purchase plan?

Answered: 1 week ago