Practice (Suppliers, Parts, Catalog)

Slides:



Advertisements
Similar presentations
SQL: The Query Language Part 2
Advertisements

Practice for SQL and Constraints (Product-PC-Laptop-Printer)
COP4540 Database Management System Midterm Review
For(int i = 1; i
1 Relational Algebra & Calculus Chapter 4, Part A (Relational Algebra) Query Formulation Exercise.
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.
Database Languages Chapter 7. The Relational Algebra.
TURKISH STATISTICAL INSTITUTE 1 /34 SQL FUNDEMANTALS (Muscat, Oman)
1 Advanced SQL Queries. 2 Example Tables Used Reserves sidbidday /10/04 11/12/04 Sailors sidsnameratingage Dustin Lubber Rusty.
COP-5725 Practice Exercises
1 TRC vs DRC 한욱신. 2 Queries in TRC and DRC  TRC Q = {t| f(t)} where t is a (free) tuple variable and f(t) is a well-formed formula  DRC.
Chapter (7): Advanced SQL
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5 Modified by Donghui Zhang.
(Uses slides from Fernando Farfan and Eduardo J. Ruiz
A DVANCED SQL Joe Meehean 1. SQL S ET O PERATIONS Syntax SELECT column1, column2, … FROM table1… WHERE conditions SET_KEYWORD SELECT column1, column2,
Unit 2 Find the Midpoint of a Line Segment Learning Goals: I can find the midpoint of a line segment by applying what I know about averages. I can solve.
 CS 405G: Introduction to Database Systems Lecture 7: Relational Algebra II Instructor: Chen Qian Spring 2014.
Rates of Change.
ECE 2011 Classroom Exercise The voltage across the 22.5 Ω resistor is 90 Volts.
Structured Query Language – Continued Rose-Hulman Institute of Technology Curt Clifton.
1 Rewriting Minus Queries Using Not In SELECT S.sname FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ MINUS.
RELATIONAL ALGEBRA (III) Prof. Sin-Min LEE Department of Computer Science.
RELATIONAL ALGEBRA (II) Prof. Sin-Min LEE Department of Computer Science.
Midterm Review/Practice for SQL and Constraints. Exercise – Suppliers and Parts Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price)
Chapter 5 Review.
CHAPTER 6 Polynomials: Factoring (continued) Slide 2Copyright 2011, 2007, 2003, 1999 Pearson Education, Inc. 6.1Multiplying and Simplifying Rational Expressions.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5.
Section 7 –4 Area of Trapezoids, Rhombuses, & Kites
Section 7 –7 Areas of Circles & SEctors
1 SELECT statement. 2 Sample database Supplier Part supplies (0,n) colour s# snamep# pname amount citydob price qualitydate.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5.
Relational Algebra II. Semantics - where A WHERE X  Y –  : an operator like =, >, … Result of restriction A by the condition X  Y is A relation –with.
1 Lecture 04: SQL Wednesday, January 11, Outline Two Examples Nulls (6.1.6) Outer joins (6.3.8) Database Modifications (6.5)
Graphing Quadratic Functions in Standard Form y = ax 2 + bx + c.
Structured Query Language Chris Nelson CS 157B Spring 2008.
Ingres 2006 release 2 ANSI date/time data types Derived Tables.
R EVIEW. 22 Exam Su 3:30PM - 6:30PM 2010/12/12 Room C9000.
Data Manipulation 21 After this lecture, you should be able to:  Use SQL SELECT statement effectively to retrieve the data from multiple related tables.
Calculus 3.9: Rates of Change in the Sciences. Rates of Change: Economics.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
Objective: Write and solve multistep equations. Standards Addressed: C: Create and interpret equations that model problem situations E: Select.
Section 13.1 – 13.2 Increasing/Decreasing Functions and Relative Extrema.
COMP3030 Database Management System Final Review
Reading Graphs A graph of a function is shown. Using the graph, find the indicated function values; that is, given the input, find the output. Rewrite.
An Introduction to SQL For CS Overview of SQL  It is the standard language for relational systems, although imperfect  Supports data definition.
SQL Miscellaneous Topics. Views A database view is: – a virtual or logical table based on a query. – a stored query. CREATE VIEW viewname AS query; –CREATE.
CSCI 4333 Database Design and Implementation – Exercise (2) Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
CS 3630 Database Design and Implementation. Where Clause and Aggregate Functions -- List all rooms whose price is greater than the -- average room price.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
1 Indexes ► Sort data logically to improve the speed of searching and sorting operations. ► Provide rapid retrieval of specified rows from the table without.
An urn contains 1 green, 2 red, and 3 blue marbles. Draw two without replacement. 1/6 2/6 3/6 2/5 3/5 1/5 3/5 1/5 2/5 2/30 3/30 2/30 6/30 3/30 6/30.
Essential Question How do we use derivatives to define rates of change? Thursday, September 17 Chapter 3 Review.
Unit 8 Section : Hypothesis Testing for the Mean (σ unknown)  The hypothesis test for a mean when the population standard deviation is unknown.
CHAPTER 3 Whole Numbers Slide 2Copyright 2011 Pearson Education, Inc. 3.1Least Common Multiples 3.2Addition and Applications 3.3Subtraction, Order, and.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Basic SQL Queries.
SQL Exercises. 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)
Structured Query Language IV Asma Ahmad (C. J. Date) Database Systems.
How to: SQL By: Sam Loch.
Basic SQL Queries Go over example queries, like 10 > ALL.
Lecture 05: SQL Wednesday, January 12, 2005.
Outerjoins, Grouping/Aggregation Insert/Delete/Update
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
Aggregation.
Relation (Table) Row/Tuple/Record Column/Attribute/Field name birth
Question Which of the following plays an important role in representing information about the real world in a database? Explain briefly 1)DDL.
CSCI 6315 Applied Database Systems – Exercise (3)
Christopher Thielen, Lead Application Developer, DSS IT
CS 142 Lecture Notes: Relational Databases
실습 4주차.
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
Presentation transcript:

Practice (Suppliers, Parts, Catalog)

Exercise – Suppliers and Parts Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) Find the names of suppliers who supply every part. Find the names of suppliers who supply every red part. Find the part names supplied by IBM and no one else. Find the sid’s of suppliers who charge more for some part that the average price of that part (averaged over all suppliers who supply that part.) For each part, find the name of the supplier who charges the least for that part. For all suppliers that supply more than three red parts find how many green parts they supply.

Creation of Tables CREATE TABLE Suppliers ( sid INT, sname VARCHAR(20), address VARCHAR(20) ); CREATE TABLE Parts ( pid INT, pname VARCHAR(10), color VARCHAR(10) CREATE TABLE Catalog ( price INT

Find the names of suppliers who supply every part. Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) Find the names of suppliers who supply every part. SELECT sname FROM Suppliers X WHERE NOT EXISTS ( --If a supplier supplies all the parts, then this subq. should return empty result (SELECT pid FROM Parts) MINUS (SELECT pid FROM Catalog WHERE sid=X.sid) );

b) Find the names of suppliers who supply every red part. Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) b) Find the names of suppliers who supply every red part. SELECT sname FROM Suppliers X WHERE NOT EXISTS ( (SELECT pid FROM Parts WHERE color='red') MINUS (SELECT pid FROM Catalog NATURAL JOIN Parts WHERE sid=X.sid AND color='red') );

c) Find the part names supplied by IBM and no one else. Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) c) Find the part names supplied by IBM and no one else. CREATE VIEW SupCatPar AS SELECT sid, sname, address, pid, pname, color, price FROM Suppliers NATURAL JOIN Catalog NATURAL JOIN Parts; SELECT pname FROM SupCatPar WHERE sname='IBM' AND pid NOT IN ( SELECT pid WHERE sname<>'IBM' );

Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) d) Find the sid’s of suppliers who charge more for some part that the average price of that part (averaged over all suppliers who supply that part.) SELECT sid FROM Catalog X WHERE price > ( SELECT AVG(price) FROM Catalog WHERE pid=X.pid );

Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) e) For each part, find the name of the supplier who charges the least for that part. SELECT pname, sname FROM SupCatPar X WHERE X.price = ( SELECT MIN(price) FROM Catalog WHERE pid=X.pid );

Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price) f) For all suppliers that supply more than three red parts find how many green parts they supply. CREATE VIEW SIDs_RED AS SELECT sid FROM SupCatPar WHERE color='red' GROUP BY sid HAVING COUNT(pid)>3; CREATE VIEW SupCatPar_Green AS SELECT * WHERE color='green'; SELECT sname, COUNT(pid) AS number_green_parts FROM SIDs_RED NATURAL LEFT OUTER JOIN SupCatPar_Green GROUP BY sid, sname; DROP VIEW SIDs_RED; DROP VIEW SupCatPar_Green;