Order by, Group by – HP Intelligent Management Center Standard Software Platform User Manual

Page 703

Advertising
background image

ORDER BY

The ORDER BY clause specifies that the database records retrieved be
sorted according to the values in a specific field. If you do not use the ORDER
BY clause, the program retrieves records in the order in which they appear
in the original database. If you specify more than one field after the ORDER
BY clause, the program sorts the records according to the values in the first
field specified, then, within that sort, the program sorts the records by the
values in the second field specified, and so on. The following SQL statement
uses the ORDER BY clause:

SELECT

MYTABLE.'COMPANY',
MYTABLE.'CITY',
MYTABLE.'STATE'

FROM

'MYTABLE' MYTABLE

ORDER BY

MYTABLE.'STATE' ASC,
MYTABLE.'CITY' ASC

Note:

ASC indicates that the values in the field are sorted in ascending order rather
than descending order (DESC). Ascending order sorts letters from A to Z
and numbers from 0 to 9.

GROUP BY

The GROUP BY clause retrieves a set of summary data. Instead of retrieving
the data itself, GROUP BY groups the data and summarizes each group with
an SQL aggregate function. The server returns only the summarization
information for each group to Crystal Reports.

For example:

SELECT

MYTABLE.'STATE',
MYTABLE.'ZIPCODE',
SUM (MYTABLE.'SALES')

FROM

'MYTABLE' MYTABLE

GROUP BY

Crystal Reports 2008 SP3 User's Guide

703

25

Understanding Databases

Using SQL and SQL databases

Advertising