Docsity

Data Manipulation Analysis - Lecture Notes | COP 5725, Study notes of Computer Science

Partial preview of the text

Download Data Manipulation Analysis - Lecture Notes | COP 5725 and more Study notes Computer Science in PDF only on Docsity!

What you should have learned after this lecture ... ‰ what the main^ data manipulation language

( DML ) commands of SQL are

‰^ grouping

in SQL ‰^ sorting^

in SQL

Grouping ‰^ general form of the select-from-where clause^ selectfrom^ [ where^ ][ group by

<group-by-expression> [, <group-by-expression>]*][ having ][ order by <order-expression>] ‰^ group by

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

C

2137 Kant

C

2126 Russel

C

2125 Sokrates

C

2134 Augustinus

C

2127 Kopernikus

C

2133 Popper

C