Get startedGet started for free

Formatting - player BMI

In this exercise, you are working with a team on a data analytics project, which has been asked to provide some statistics on NBA players to a health care company. You want to create a query that returns the Body Mass Index (BMI) for each player from North America.

$$BMI = \dfrac{weight (kg)}{height (cm)^2}$$

A colleague has passed you a query he was working on:

select PlayerName, Country,
round(Weight_kg/SQUARE(Height_cm/100),2) BMI 
from Players Where Country = 'USA' 
Or Country = 'Canada'
order by BMI

To make some sense of the code, you want to structure and format it in a way that is consistent and easy to read.

This exercise is part of the course

Improving Query Performance in SQL Server

View Course

Exercise instructions

  • Change all SQL syntax (clauses, operators, and functions) to UPPERCASE.
  • Make sure all SQL syntax begins on a new line.
  • Add an indent to the calculated BMI column and OR statement.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

select PlayerName, Country,
round(Weight_kg/SQUARE(Height_cm/100),2) BMI
from Players Where Country = 'USA'
Or Country = 'Canada'
order by BMI;
Edit and Run Code