SQL Exercises. 1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

Slides:



Advertisements
Similar presentations
SQL: The Query Language Part 2
Advertisements

COP4540 Database Management System Midterm Review
Complex Integrity Constraints in SQL. Constraints over a Single Table Table Constraint: Create TABLE Sailors (sid INTEGER, sname CHAR(10), rating INTEGER,
1 Design Process - Where are we? Conceptual Design Conceptual Schema (ER Model) Logical Design Logical Schema (Relational Model) Step 1: ER-to-Relational.
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)
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.
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
(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,
Schema BankWorld Customer(C_Name, C_Street, C_City) Depositor(Account_#, C_Name) Loan(Loan_#, B_Name, Amount) Borrower(C_Name, Loan_#)
INFS614, Fall 08 1 Relational Algebra Lecture 4. INFS614, Fall 08 2 Relational Query Languages v Query languages: Allow manipulation and retrieval of.
SQL and Relational Algebra Zaki Malik September 02, 2008.
CS411 Database Systems Kazuhiro Minami 06: SQL. Join Expressions.
Practice (Suppliers, Parts, Catalog)
Murali Mani The Relational Model. Murali Mani Why Relational Model? Currently the most widely used Vendors: Oracle, Microsoft, IBM Older models still.
1 Rewriting Intersect Queries Using In SELECT S.sid FROM Sailors S, Boats B, Reserves R WHERE S.sid = R.sid and R.bid = B.bid and B.color = ‘red’ INTERSECT.
Midterm Review/Practice for SQL and Constraints. Exercise – Suppliers and Parts Suppliers(sid,sname,address) Parts(pid,pname,color) Catalog(sid, pid,price)
Cursors in Pl/SQL Database 1. Practice. Sample Database The schema of the sample database is the following: Drinkers (name, occupation, birthday, salary)
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5.
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.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Data Manipulation 11 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and other programming.
1 Exercises of SQL uAnswer the following questions, based on the database below. wSupplier (SNO, SNAME, STATUS, CITY) wPart(PNO, PNAME, COLOR, WEIGHT)
Review for Midterm. Problem 2.7 HasPriPhy Patients address name ssn age Doctors exp_year name ssn specialty Pharmacies name address phone PharmCo name.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L6_SQL(1) 1 SQL: Queries, Constraints, Triggers Chapter 5 – Part 1.
INLS 623– S QL Instructor: Jason Carter. SQL SELECT DISTINCT SELECT DISTINCT column_name, column_name FROM table_name ;
Chapter 10 Views. Topics in this Chapter What are Views For? View Retrievals View Updates Snapshots SQL Facilities.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Algebra.
1 From E-R Model to Relational Model. 2 Entity type sid#name address house#street pcode Student.
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.
Algebra1 After this lecture, you should be able to:  Understand the differences between SQL (Structured Query Language) and Relational Algebra expressions.
Chapter 8 Database Redesign We only discuss complex sub-queries.
COMP3030 Database Management System Final Review
CMPT 258 Database Systems SQL Queries (Chapter 5).
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
Advanced Databases More Advanced PL/SQL Programing 1.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 SQL: Queries, Programming, Triggers Chapter 5.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Basic SQL Queries.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Advanced SQL: Aggregation and Null Values.
1 CS122A: Introduction to Data Management Lecture 8 Introduction to SQL Instructor: Chen Li.
Structured Query Language IV Asma Ahmad (C. J. Date) Database Systems.
BBM471 – Database Management Systems Fall 2013 Dr. Nazlı İkizler Cinbiş.
Relational Calculus Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
Relational Algebra Database Management Systems, 3rd ed., Ramakrishnan and Gehrke, Chapter 4.
STRUCTURE OF PRESENTATION :
Basic SQL Queries Go over example queries, like 10 > ALL.
Lecture 05: SQL Wednesday, January 12, 2005.
COP Introduction to Database Structures
Aggregation.
Database Applications (15-415) SQL-Part II Lecture 9, February 04, 2018 Mohammad Hammoud.
Database Systems 10/13/2010 Lecture #4.
Relational Databases The Relational Model.
Relational Databases The Relational Model.
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)
Φροντιστήριο SQL (από το βιβλίο του Date)
Unit 7 Normalization (表格正規化).
STRUCTURE OF PRESENTATION :
실습 4주차.
STRUCTURE OF PRESENTATION :
CS 405G: Introduction to Database Systems
Presentation transcript:

SQL Exercises

1) Names of suppliers. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

2) Names of suppliers who supply some part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

3) Names of suppliers who supply some red part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

4) Names of suppliers who supply some red part and are at 221 Packer Street. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

5) Names of suppliers who supply some red part or are at 221 Packer Street. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

6) Pairs of sids (sid1, sid2) such that the sid1 is more expensive for some part than sid2 Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

7) Pids of the most expensive parts supplied by supplier s versions! (using ALL, NOT EXISTS, EXCEPT) Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

8) Pids of parts supplied which are only supplied at less than $200. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

9) Sids of suppliers who supply every red part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

10) Sids of suppliers who supply every part that is either red or green part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

11) Sids of suppliers who supply every red part or every green part. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

12) Find the average price of red parts Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

13) For each color, find the number of parts with that color. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

14) For each color, find the number of parts with that color, provided that the average cost (of parts with that color) is at least 40. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

15) Find the number of parts that are not supplied by any supplier Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

16) Find the total number of tuples in all three tables. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

17) Find the average number of tuples per table in the three database tables Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

18) Find names of suppliers who supply at least 6 different parts Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

19) Find all suppliers who supply a part with an unknown (i.e., null) color. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

20) For each supplier, return the number of parts supplied by that supplier, which have an unknown (i.e., null) color. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

21) Find the names of all parts whose color starts with the letter b. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

22) For each part in Catalog, return its pid, along with the cheapest price and the most expensive price, for which it is supplied. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)

23) For each part in Part, return pid, along with the cheapest price and the most expensive price, for which it is supplied. If the part is not supplied, then the cheapest and most expensive prices should be null. Suppliers(sid, sname, address) Parts(pid, pname, color) Catalog(sid, pid, cost)