Get Started

Calculating standard deviation

Calculating the standard deviation is quite common when dealing with numeric columns. In this exercise, you will calculate the running standard deviation, similar to the running total you calculated in the previous lesson.

This is a part of the course

“Intermediate SQL Server”

View Course

Exercise instructions

Create the window, partition by TerritoryName and order by OrderDate to calculate a running standard deviation of OrderPrice.

Hands-on interactive exercise

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

SELECT OrderDate, TerritoryName, 
       -- Calculate the standard deviation
	   ___ 
       OVER(PARTITION BY TerritoryName ORDER BY OrderDate) AS StdDevPrice	  
FROM Orders

This exercise is part of the course

Intermediate SQL Server

IntermediateSkill Level
4.3+
32 reviews

In this course, you will use T-SQL, the flavor of SQL used in Microsoft's SQL Server for data analysis.

In the final chapter of this course, you will work with partitions of data and window functions to calculate several summary stats and see how easy it is to create running totals and compute the mode of numeric columns.

Exercise 1: Window functions in T-SQLExercise 2: Window functions with aggregations (I)Exercise 3: Window functions with aggregations (II)Exercise 4: Common window functionsExercise 5: Do you know window functions?Exercise 6: First value in a windowExercise 7: Previous and next valuesExercise 8: Increasing window complexityExercise 9: Creating running totalsExercise 10: Assigning row numbersExercise 11: Using windows for statistical functionsExercise 12: Calculating standard deviation
Exercise 13: Calculating mode (I)Exercise 14: Calculating mode (II)

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free