



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




( DML ) commands of SQL are
^ grouping
in SQL ^ sorting^
in SQL
Grouping ^ general form of the select-from-where clause^ selectfrom^ [ where^
<group-by-expression> [, <group-by-expression>]*][ having
clause − A “group-by-expression” is an expression that refers only to those attributes thatare not^ used for computing the aggregate. Tuples with equal values for the speci-fied value are summarized in groups (partitions). − For each group the query produces a new tuple in the result relation. Hence, onlyattributes with one value per group are permitted after the
select^ clause.
^ having^ clause^ −^ choice of groups with respect to a condition which may contain only argumentswith one value per group
^ Since in the result relation each group is represented by exactly one tuple, in the^ select^ clause only aggregate functions can appear, or attributes that are used forgrouping, i.e., that are also used in the
group by^ clause.
Sorting ^ frequently a sorted output is required^ →^ DBMS needs sort operator, sorting is expensive ^ sorted output with the
order by^ clause with respect to one or more attributes −^ order by
[ asc^ |^ desc
]^ A , ..., [ asc^1
|^ desc ]^ An^
A attribute i^
−^ sorting order:^ +^ keyword
asc^ = ascending (default) + keyword desc^ = descending ^ The^ order by
clause is the last clause in an SQL command.
^ example: Determine personell id, name and rank of all professors; sort the resulttuples in descending order by rank and in ascending order by name.^ select^ pers-id, name, rank
from^ professors
order by^ rank
desc , name
asc
−^ attribute^ rank^ main sorting condition, attribute
name^ minor sorting condition
professorspers-id name^
rank 2136 Curie
2137 Kant
2126 Russel
2125 Sokrates
2134 Augustinus
2127 Kopernikus
2133 Popper