Database Reference
In-Depth Information
The query results appear in Figure 3-22.
86
Customers with
balances between
$1,000 and $5,000
FIGURE 3-22
Query results
The BETWEEN operator is not an essential feature of SQL; you can use the AND operator to obtain the
same results. Using the BETWEEN operator, however, does make certain SELECT commands easier to
construct.
COMPUTED FIELDS
Similar to QBE, you can include fields in queries that are not in the database but whose values you can com-
pute from existing database fields. A field whose values you derive from existing fields is called a computed
field or calculated field. Computed fields can involve addition (
þ
), subtraction (
-
), multiplication (*), or divi-
sion (/). The query in Example 12, for example, uses subtraction.
EXAMPLE 12
List the number, name, and available credit for all customers.
There is no field in the database that stores available credit, but you can compute it using two fields that
are present in the database: CreditLimit and Balance. The query design shown in Figure 3-23 creates a new
field named AvailableCredit, which is computed by subtracting the value in the Balance field from the value
in the CreditLimit field (AvailableCredit
Balance). By using the word AS after the computa-
tion, followed by AvailableCredit, you can assign a name to the computed field.
CreditLimit
-
¼
Computed
ield name
Expression
FIGURE 3-23
SQL query with a computed field
Search WWH ::




Custom Search