SQL: The Query Language

9/29/98


Click here to start


Table of Contents

SQL: The Query Language

Example Instances

Basic SQL Query

Conceptual Evaluation Strategy

Example of Conceptual Evaluation

A Note on Range Variables

Find sailors who’ve reserved at least one boat

Expressions and Strings

Find sid’s of sailors who’ve reserved a red or a green boat

Find sid’s of sailors who’ve reserved a red and a green boat

Nested Queries

Nested Queries with Correlation

More on Set-Comparison Operators

Rewriting INTERSECT Queries Using IN

Division in SQL

Aggregate Operators

Find name and age of the oldest sailor(s)

GROUP BY and HAVING

Queries With GROUP BY and HAVING

Conceptual Evaluation

Find the age of the youngest sailor with age ? 18, for each rating with at least 2 such sailors

For each red boat, find the number of reservations for this boat

Find the age of the youngest sailor with age > 18, for each rating with at least 2 sailors (of any age)

Find those ratings for which the average age is the minimum over all ratings

Null Values

Embedded SQL

Cursors

Cursor that gets names of sailors who’ve reserved a red boat, in alphabetical order

Embedding SQL in C: An Example

Summary

Author: Joe Hellerstein/Raghu Ramakrishnan

Email: cs186@cory.eecs.berkeley.edu

Home Page: http://www-inst.eecs.berkeley.edu/~cs186/