Example
The following example uses the
SELECT dog_name, AVG(dog_IQ) AS avg_IQ
FROM Dogs
WHERE breed LIKE '%Terrier';
Arbitrary expressions in aggregate functions
ColdFusion supports aggregate functions of any arbitrary expression, as follows:
SELECT lorange, count(lorange+hirange)
FROM roysched
GROUP BY lorange;
Aggregate functions in arbitrary expressions
ColdFusion supports mathematical expressions that include aggregate functions, as follows:
SELECT MIN(lorange) + MAX(hirange)
FROM roysched
GROUP BY lorange;
Using group by and having expressions
ColdFusion supports the use of any arbitrary arithmetic expression, as long as it is referenced by
an alias.
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
ColdFusion 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>]
function to retrieve the average IQ of all terriers:
AVG()
Query of Queries user guide
469
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers