Table of Contents
Previous Section Next Section

Chapter 5: Performing Calculations and using Functions

Overview

A number of times over the past few chapters you found that selecting data based on the simple column name didn't meet your needs. Instead you needed to combine values or calculate new values based on the data in your database, such that the values you obtained in your results were ready for you to use. You have, for example, concatenated strings to create columns more suited to applications, and you've also performed simple calculations involving numerical data, such as multiplying the values of two columns together.

In this chapter, you're going to look at calculations in more detail, outlining what is and isn't possible, as well as the syntax required. You're also going to examine several of the important single row functions (which act on a single row, rather than a set of rows, and return a value) that SQL provides for you. These allow you to perform all sorts of operations. You can, for example, do the following:

  • Perform various mathematical and trigonometric actions on data

  • Reformat dates and times

  • Manipulate string values

  • Convert between different data types

Along the way, you'll see how you can use these functions in conjunction with some of the aggregate functions you explored in the previous chapter, which act on a set of rows and provide summary data to powerful effect.

You'll finish up by discussing how to create your own custom functions for when the built-in versions don't quite meet your specific needs.


Table of Contents
Previous Section Next Section