CS 330
Lecture 8
Examples


Aggregate functions

  1. Find the average account balance at the Perryridge branch.
  2. Find the average account balance at every branch.
  3. Find the number of depositors for each branch.
  4. Find those branches where the average account balance is > 1200.
  5. Find the average balance for all accounts.
  6. Find the number of tuples in customer relation.
  7. Find the average balance for each customer who lives in Harrison and has at least 3 accounts.

Nested Queries

  1. Find all customers who have both a loan and an account.
  2. Find all customers who have both an account and a loan at the Perryridge branch.
  3. Find all customers who do have a loan, but do not have an account at the bank.

Set Comparisons.

    Find names of all branches that have assets greater than those of at least one branch located in Brooklyn.
  1. Find names of all branches that have assets greater than the assets of each branch located in Brooklyn.
  2. Find the branch that has the highest average balance.

Empty relations.

  1. Find all customers who have both an account and a loan at the bank.
  2. Find all customers who have an account at all branches located in Brooklyn.

Test for absence of duplicates.

  1. Find all customers who have only one account at the Perryridge branch.
  2. Find all customers who have at least two accounts at the Perryridge branch.

Ileana Streinu