Calculating Fields - Exercise

Contact Us or call 1-877-932-8228
Calculating Fields - Exercise

Calculating Fields

Duration: 10 to 20 minutes.

In this exercise, you will practice writing SELECT statements with calculated fields.

  1. Create a report that shows the unit price, quantity, discount, and the calculated total price using these three fields.
    • Note for SQL Server users only: You will be using the Order Details table. Because this table name has a space in it, you will need to put it in double quotes in the FROM clause (e.g, FROM "Order Details").
  2. Write a SELECT statement that outputs the following.

Solution:

AdvancedSelects/Solutions/Calculations.sql
/******************************
SQL Server Solutions
******************************/
SELECT UnitPrice, Quantity, Discount, UnitPrice * Quantity * (1-Discount) AS TotalPrice
FROM "Order Details";

SELECT FirstName + ' ' + LastName + ' can be reached at x' + Extension + '.' AS ContactInfo
FROM Employees;

/******************************
Oracle Solutions
******************************/
SELECT UnitPrice, Quantity, Discount, UnitPrice * Quantity * (1-Discount) AS TotalPrice
FROM Order_Details;

SELECT FirstName || ' ' || LastName || ' can be reached at x' || Extension || '.' AS ContactInfo
FROM Employees;

/******************************
MySQL Solutions
******************************/
SELECT UnitPrice, Quantity, Discount, UnitPrice * Quantity * (1-Discount) AS TotalPrice
FROM Order_Details;

SELECT CONCAT(FirstName, ' ', LastName, ' can be reached at x', Extension, '.') AS ContactInfo
FROM Employees;
Next