Review Session Monday, Oct 8 Shipra Agrawal. Announcements New Gradiance assignment deadline Wednesday, Oct 10 Please read FAQs for assignments.

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

1 Lecture 5: SQL Schema & Views. 2 Data Definition in SQL So far we have see the Data Manipulation Language, DML Next: Data Definition Language (DDL)
COP4540 Database Management System Midterm Review
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
1 Database Systems 10.8, 2008 Lecture #4. 2 Course Administration Assignment #1 is due next Wed (outside 336/338). Course slides will now have black background.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Huiswerk Lees delen 3.2, 3.3 van hoofdstuk 3. opgaven voor hoofdstuk 2: modelleeropgave 5.
CH4 EXERCISES 4.2. Given two relations R1 and R2, where R1 contains N1 tuples, R2 contains N2 tuples, and N2 > N1 > 0, give the min and max possible sizes.
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
Chapter 6 Additional Relational Operations Dr. Bernard Chen Ph.D. University of Central Arkansas Fall 2008.
1 Exercise 1  Given the following tables: employee (person_name, street, city)‏ works (person_name, company_name, salary)‏ company (company_name, city)‏
Structured Query Language NEU – CCIS – CSU430 Tony.
Data Warehousing/Mining 1 Data Warehousing/Mining Comp 150 Aggregation in SQL (not in book) Instructor: Dan Hebert.
Information Resources Management February 27, 2001.
DB opgaven 2 Opgaven 2 Geert-Jan Houben.
--The SQL Query Language DML--1 LIKE  LIKE allows to select character strings which have some element in common by using wild cards:  Wild cards:  “%”
SQL SQL stands for Structured Query Language SQL allows you to access a database SQL is an ANSI standard computer language SQL can execute queries against.
Slides adapted from A. Silberschatz et al. Database System Concepts, 5th Ed. SQL - part 2 - Database Management Systems I Alex Coman, Winter 2006.
One More Normal Form Consider the dependencies: Product Company Company, State Product Is it in BCNF?
Relation Decomposition A, A, … A 12n Given a relation R with attributes Create two relations R1 and R2 with attributes B, B, … B 12m C, C, … C 12l Such.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
The Relational Model The relational model refers to a class of data models that have relations as the data structure, and incorporate some of all the query.
Relational Model Concepts. The relational model represents the database as a collection of relations. Each relation resembles a table of values. A table.
Query Processing: Relational Algebra
Structured Query Language. Group Functions What are group functions ? Group Functions Group functions operate on sets of rows to give one result per group.
Information Resource Engineering SQL4. Recap - Ordering Output  Usually, the order of rows returned in a query result is undefined.  The ORDER BY clause.
SQL-5 (Group By.. Having). Group By  Need: To apply the aggregate functions to subgroups of tuples in a relation, where the subgroups are based on some.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts - 5 th Edition, Oct 5, 2006 Example.
1Database Management Systems Exercise II  Consider the following relational schemas:  employee (person_name, street, city)  company (company_name, city)
1 CSCE Database Systems Anxiao (Andrew) Jiang The Database Language SQL.
COMP3030 Database Management System Final Review
1/18/00CSE 711 data mining1 What is SQL? Query language for structural databases (esp. RDB) Structured Query Language Originated from Sequel 2 by Chamberlin.
Relational Algebra Sample Questions.
Ch. 4 Relational Algebra (2) Exercises. Algebra (3) 데이터베이스시스템 2 Queries in Ch.4 (p.161, p.166) EMPLOYEE (p.161) EmpNoEmpNameTitleManagerSalaryDNO 2106.
ORT Braude, CSE 61309, ©2004 Gary Schloss Exam Question #1: ER, RA & SQL Consider a DB schema with the following relations: - Student (s#, sname) - Professor.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Relational State Assertions These slides.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Grouping These slides are licensed under.
Hassan Tariq INTRODUCTION TO SQL What is SQL? –When a user wants to get some information from a database file, he can issue a query. – A query is a user–request.
ASET Relational Algebra continues…. ASET Rename Operation Allows us to name, and therefore to refer to, the results of relational-algebra expressions.
SQL Aggregeringsfunktioner. AGGREGATE FUNCTIONS Include COUNT, SUM, MAX, MIN, and AVG Query 15: Find the maximum salary, the minimum salary, and the average.
Day 5 - More Complexity With Queries Explanation of JOIN & Examples Explanation of JOIN & Examples Explanation & Examples of Aggregation Explanation &
CSE 326: Data Structures Lecture #22 Databases and Sorting Alon Halevy Spring Quarter 2001.
Advanced Accounting Information Systems Day 12 Understanding the SQL Language September 21, 2009.
Structured Query Language (Data Manipulation Language)
Chapter # 6 The Relational Algebra and Calculus
Chapter 3 Introduction to SQL(3)
CPSC-310 Database Systems
Relational Algebra at a Glance
The Database Exercises Fall, 2009.
Relational Algebra - Select & Project
SQL-lab Download sql script file sailors.txt
Chapter 2: Intro to Relational Model
Generalization.
Database Systems 10/13/2010 Lecture #4.
CS 3630 Database Design and Implementation
Session 3 Welcome: To session 3-the sixth learning sequence
Instructor: Mohamed Eltabakh
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Relational Algebra Sample Questions.
Where are we? Until now: Modeling databases (ODL, E/R): all about the schema Now: Manipulating the data: queries, updates, SQL Then: looking inside -
One-Pass Algorithms for Database Operations (15.2)
Query Functions.
In Class Exercises Phil Tayco Slide version 1.1 San Jose City College
Introduction to Database
BUS2206 Access Lab Queries Second Term,
Set Operations Union Intersect Minus.
Syllabus Introduction Website Management Systems
Instructor: SAMIA ARSHAD
Aggregate functions Objective- understand and able to use aggregate functions in select statement Aggregate functions are used to implement calculation.
Topic - DML - Select statement
Instructor: Zhe He Department of Computer Science
Presentation transcript:

Review Session Monday, Oct 8 Shipra Agrawal

Announcements New Gradiance assignment deadline Wednesday, Oct 10 Please read FAQs for assignments

Select-From-Where Statements SELECT desired attributes FROM one or more tables WHERE condition about tuples of the tables

Exercise Consider database Product(name, price, category) Output  each product name with its price in cents  Also mark the products with price >10$ and category=‘beverage’ as ‘expensive’ and others as ‘reasonable’

Solution SELECT name, price*100, ‘expensive’ FROM Product WHERE price >10 AND category = ‘beverage’ UNION SELECT name, price*100, ‘reasonable’ FROM Product WHERE price ‘beverage’

Multirelation queries Consider database schema employee( employee-name, street, city) works( employee-name, company-name, salary) company( company-name, city) manages( employee-name, manager- name)

Exercise 1 (3-way join) Find all employees who live in the same cities as the companies for which they work SELECT employee-name FROM employee, works WHERE employee.employee-name = works.employee-name AND works.company- name = company.company-name AND employee.city = company.city

Exercise 2 Find all employees in the database who live on the same city and streets as their manager. SELECT e1.employee-name FROM employee e1,employee e2, manages WHERE e1.employee-name = manages.employee-name AND e2. employee-name = manages.manager-name AND e1.street = e2.street AND e1.city = e2.city

Exercise 3 Find all employees who earn more than average salary of all employees of their company SELECT employee-name FROM works w1, (SELECT AVG(salary) AS avg-salary, company-name FROM works GROUP BY company-name) w2 WHERE w1.company-name = w2.company-name AND w1.salary>w2.avg-salary

Exercise 4 Find those companies whose employees earn a higher salary, on average than the average salary at First Bank Corporation. SELECT company-name FROM works GROUP BY company-name HAVING AVG(salary)> (SELECT AVG(salary) FROM works GROUP BY company-name HAVING company-name = ‘First Bank Corporation’)

Exercise 5 Assume that the companies may be located in several cities. Find all the companies located in every city in which Small Bank corporation is located. SELECT company-name FROM( SELECT c1.company-name,c1.city FROM company c1, company c2 WHERE c1.city=c2.city AND c2.company-name = ‘Small Bank Corporation’ ) R GROUP BY company-name HAVING COUNT(DISTINCT city) = (SELECT COUNT(DISTINCT city) FROM company GROUP BY company.company-name HAVING company-name = ‘Small Bank Corporation’)

Exercise 6 Find all employees who earn more than each employee of ‘Small Bank Corporation’ Select employee-name From employee Where employee-name NOT IN ( SELECT employee-name FROM works w1,works w2 WHERE w1.salary < w2.salary AND w2.company- name = ‘Small Bank Corporation’ )

Exercise 6 (contd..) Find all employees who earn more than each employee of ‘Small Bank Corporation’ Select employee-name From employee Where name NOT IN ( SELECT employee-name FROM works w1, (SELECT salary FROM works WHERE company-name=‘Small Bank Corporation’) w2 WHERE w1.salary < w2.salary )

Exercise 6 Find all employees who earn more than each employee of ‘Small Bank Corporation’ Select employee-name From works Where salary > ( SELECT MAX(salary) FROM works GROUP BY company-name HAVING company-name = ‘Small Bank Corporation’ )

Questions?