Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 449

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Examples
The following code is correct:
SELECT (lorange + hirange)/2 AS midrange,
COUNT(*)
FROM roysched
GROUP BY midrange;
The following code is correct:
SELECT (lorange+hirange)/2 AS x,
COUNT(*)
FROM roysched GROUP BY x
HAVING x > 10000;
The following code is not supported in Query of Queries:
SELECT (lorange + hirange)/2 AS midrange,
COUNT(*)
FROM roysched
GROUP BY (lorange + hirange)/2;
Using ORDER BY clauses
Query of Queries supports the ORDER BY clause to sort. Make sure that it is the last clause in your SELECT statement.
You can sort by multiple columns, by relative column position, by nonselected columns. You can specify a descending
sort direction with the DESC keyword (by default, most RDBMS sorts are ascending, which makes the ASC keyword
unnecessary).
Syntax
order_by_column ::= ( <IDENTIFIER> | <INTEGER_LITERAL> ) [<ASC> | <DESC>]
Example
The following example shows a simple sort using an ORDER BY clause:
SELECT acetylcholine_levels, dopamine_levels
FROM results
ORDER BY dopamine_levels
The following example shows a more complex sort; results are first sorted by ascending levels of dopamine, then by
descending levels of acetylcholine. The ASC keyword is unnecessary, and is used only for legibility.
SELECT acetylcholine_levels, dopamine_levels
FROM results
ORDER BY 2 ASC, 1 DESC
Using aliases
Query of Queries supports the use of database column aliases. An alias is an alternate name for a database field or
value. Query of Queries lets you reuse an alias in the same SQL statement.
One way to create an alias is to concatenate (append) two or more columns to generate a value. For example, you can
concatenate a first name and a last name to create the value fullname. Because the new value does not exist in a
database, you refer to it by its alias. The AS keyword assigns the alias in the SELECT statement.
Examples
Query of Queries supports alias substitutions in the ORDER BY, GROUP BY, and HAVING clauses.
Last updated 1/20/2012
444

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents