user manual

Chapter 17: EJB-QL and Data Access Support 183
Support for GROUP BY
<query-method>
<method-name>findCustomerByNumber</method-name>
<method-params />
<ejb-ql>SELECT Distinct Object(c) from CustomerBean c WHERE c.no > 1000
ORDER BY c.LNAME</eql-ql>
</query-method>
<query>
You can specify either ASC (ascending) or (DESC) descending in your EJB-
QL as well. If you do not specify either, the results will be ordered ascending
by default.
For example, consider the following table:
The query:
SELECT OBJECT(e) FROM EMPLOYEE e ORDER BY e.HIRE_DATE
will produce the following result:
Support for GROUP BY
The GROUP BY clause is used to group rows in the result table prior to the
SELECT operation being performed. Consider the following table:
NAME DEPARTMENT SALARY HIRE DATE
Timmy Twitfuller Mail Room 1000 1/1/01
Sam Mackey The Closet with the
Light Out
800 1/2/02
Ralph Ossum Coffee Room 900 1/4/01
NAME DEPARTMENT SALARY HIRE DATE
Timmy Twitfuller Mail Room 1000 1/1/01
Ralph Ossum Coffee Room 900 1/4/01
Sam Mackey The Closet with the
Light Out
800 1/2/02
NAME DEPARTMENT SALARY HIRE DATE
Mike Miller Mail Room 1200 11/18/99
Timmy Twitfuller Mail Room 1000 1/1/01
Buddy Coffee Room 1000 4/13/97
Sam Mackey The Closet with the
Light Out
800 1/2/02
Todd Whitmore The Closet with the
Light Out
900 4/12/01
Ralph Ossum Coffee Room 900 1/4/01