Computed Fields and Alias
A reminder of the database we will be using:
Computed Values
Arithmetic expressions can be used to compute values as part of a SELECT query. The expressions can contain column names, numeric numbers and arithmetic operators. Whenever a value is generated by a query it is allocated its own column in the query answer table.
A computed value is temporary, it only exists within the query. This eliminates the need to store extra data which can be computed at run-time - particularly data which may change often.
Computed Fields and ALIAS Example 1
Stock value of all items with heading ‘Stock Value’.
Example 1 - Query Design
Fields and calculations: description, price, (stockLevel*price) AS 'Stock Value'
Tables: Item
Search Criteria:
Grouping:
Sort Order:
Example 1 - Implementation
Computed Fields Example 2
The company wants to run a sale, they want to reduce the prices of all processors by 20%.
Example 2 - Query Design
Fields and calculations: description, price,(price * 0.8) AS 'Sale Value'
Tables: Item
Search Criteria: WHERE category = 'Processors'
Grouping:
Sort Order: