Aan de slagGa gratis aan de slag

Column does not exist

When using WHERE as a filter condition, it is important to think about the processing order in the query. In this exercise, you want a query that returns NBA players with average total rebounds of 12 or more per game. The following formula calculates average total rebounds from the PlayerStats table;

$$Average Total Rebounds = \dfrac{(Defensive Rebounds + Offensive Rebounds)}{Games Played}$$

The first query in Step 1 returns an error. Select Run Code to view the error. The second query, in Step 2, will give you the results you want, without error, by using a sub-query.

Note that GamesPlayed is CAST AS numeric to ensure we get decimal points in our output, as opposed to whole numbers.

Deze oefening maakt deel uit van de cursus

Improving Query Performance in SQL Server

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

-- First query

SELECT PlayerName, 
    Team, 
    Position,
    (DRebound+ORebound)/CAST(GamesPlayed AS numeric) AS AvgRebounds
FROM PlayerStats
WHERE AvgRebounds >= 12;
Code bewerken en uitvoeren