Lesson 10. Creating New Columns From Existing Data (Calculated Fields)

As you have seen already, it is possible to derive new columns from existing information. So far, we have done it with strings. Now we are going to do it with math.

SQL has all the basic math operators. You can do math on numeric fields to derive new values.

Examples

An Example Arithmetic Calculation

In [ ]:
USE AdventureWorks2016

SELECT
OrderQty,
UnitPrice,
UnitPriceDiscount,
LineTotal,
OrderQty * (UnitPrice - UnitPriceDiscount) AS CalculatedLineTotal
FROM Sales.SalesOrderDetail

Copyright © 2020, Mass Street Analytics, LLC. All Rights Reserved.