SQL-5 In-Class Exercise Answer IST 210 Organization of Data IST2101.

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

SQL – Part 2 Multiple Tables CIS 324 – Chapter 5.
4d. Structured Query Language – JOIN Operation Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
Query Methods (SQL). What is SQL A programming language for databases. SQL (structured Query Language) It allows you add, edit, delete and run queries.
SQL-week5-1 In-Class Exercise Answer IST 210 Organization of Data IST2101.
4c. Structured Query Language - Built-in Functions Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
Introduction to MS Access, building tables, creating keys, creating relationships BSAD 141 Dave Novak.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Structured Query Language Chapter Three Part 3 – Inserts, Updates, Deletes.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
Fundamentals, Design, and Implementation, 9/e Chapter 6 Introduction to Structured Query Language (SQL)
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.
Structured Query Language (SQL)
SQL Views Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
PHP and SQL Server: Queries IST2101. Three-Tier Architecture Three-tier architecture means that the Web server and the DBMS are on separate servers IST2102.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
Data Modeling and Entity- Relationship Model I IST2101.
PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Download three SQL script files from wiki page.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 8: Subqueries.
SQL – Structured Query Language CIS 324 – Chapter 5.
SQL Views Appendix E DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
Fundamentals, Design, and Implementation, 9/e CPE 481 Database Processing Chapter 6 Structured Query Language (SQL) Instructor:Suthep Madarasmi, Ph.D.
1 Agenda – 03/25/2014 Login to SQL Server 2012 Management Studio. Answer questions about HW#7 – display answers. Exam is 4/1/2014. It will be in the lab.
Fundamentals, Design, and Implementation, 9/e COS 346 Day 11.
SQL Views Chapter 3A DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
Structured Query Language SQL-I
Structured Query Language (SQL) IST2101. Structured Query Language – Acronym: SQL – Pronounced as “S-Q-L” [“Ess-Que-El”] – Originally developed by IBM.
27 Oktober 2015BASIS DATA I/2009-GENAP1 SQL SELECT STATEMENT BASIS DATA I/2009-GENAP Oleh Satrio Agung Wicaksono, S.Kom., M.Kom.
Database Processing: Fundamentals, Design, and Implementation, 9/e by David M. KroenkeChapter 6/1 Copyright © 2004 Please……. No Food Or Drink in the class.
SQL for Data Retrieval. Review Questions of Previous Class Q1. Show the sum of hours worked for project with ID 1200 (use ASSIGNMENT table) – Use “SUM”
Getting to Know SQL. © Jim Hope 2002 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement TRANSFORM.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
Exam #2 Review with Answers.  The entire exam will be on the computer  You can use search engines, Oracle SQL help, notes, books, and PPT’s  You can.
Chapter 2 Views. Objectives ◦ Create simple and complex views ◦ Creating a view with a check constraint ◦ Retrieve data from views ◦ Data manipulation.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
4a. Structured Query Language - SELECT Statement Lingma Acheson Department of Computer and Information Science IUPUI CSCI N207 Data Analysis with Spreadsheets.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
STRUCTURED QUERY LANGUAGE SQL-III IST 210 Organization of Data IST210 1.
CREATE TABLE CREATE TABLE statement is used for creating relations Each column is described with three parts: column name, data type, and optional constraints.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
SQL Views Chapter 3A. Appendix Objectives Learn basic SQL statements for creating views Learn basic SQL statements for using views Understand the reasons.
SQL Select Statement IST359.
PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired.
Getting to Know SQL. © Jim Hope 2004 All Rights Reserved Data Manipulation SELECT statement INSERT INTO statement UPDATE statement DELETE statement UNION.
+ Complex SQL Week 9. + Today’s Objectives TOP GROUP BY JOIN Inner vs. Outer Right vs. Left.
The Student Registry Database Ian Van Houdt and Muna alfahad.
Drill Consider the following tables with the following fields: Student: FName, LName, StudentID, Age, Yr, Course Grades: ID, P1, P2, P3 1.Display the.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Data Modeling and Entity-Relationship Model I
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Chapter 1. Getting Started IST 210: Organization of Data IST2101.
Structured Query Language SQL-I IST 210 Organization of Data IST2101.
Structured Query Language
CS3220 Web and Internet Programming More SQL
ISQS 3358, Business Intelligence Database vs. Data Warehouse
SQL AGGREGATE FUNCTIONS
3d. Structured Query Language – JOIN Operations
Introduction to MS Access: creating tables, keys, and relationships
Chapter 2 Views.
Structured Query Language
Chapter 2 Views.
Using CASE Value expression
SQL Views Appendix C DATABASE CONCEPTS, 3rd Edition
Lecture 3 Finishing SQL
IST 318 Database Administration
SQL NOT NULL Constraint
Presentation transcript:

SQL-5 In-Class Exercise Answer IST 210 Organization of Data IST2101

Review Questions of Previous Class Q1. Show the total hours worked for project with ID 1200 (from assignment table) Q2. Count how many distinct departments in project table IST2102

3 /* Q1. Show the total hours worked for project with ID 1200 (from assignment table) */ SELECT SUM(HoursWorked) FROM ASSIGNMENT WHERE ProjectID = 1200; /* Q2. Count how many distinct departments in project table */ SELECT COUNT(distinct Department) FROM PROJECT;

Review Questions of Previous Class Q3. Group projects by departments. Show department names and number of projects associated with each department Q4. Add a constraint to Q3. Only show the departments with number of projects more than 1 IST2104

5 /* Q3 Group projects by departments. Show department names and number of projects associated with each department */ SELECT Department, COUNT(*) FROM PROJECT GROUP BY Department; /* Q4 Add a constraint to Q3. Only show the departments with number of projects more than 1 */ SELECT Department, COUNT(*) FROM PROJECT GROUP BY Department HAVING COUNT(*) > 1;

Exercise 1 IST2106 Show the names of employees who is assigned to ProjectID 1000 – First write two separate queries and then merge into one query 6 Q2. Show the names of employees with the employee numbers from Q1 Q1. Find employee numbers who is assigned to projectID 1000 EMPLOYEE ASSIGNMENT

7 /*** Exercise 1: Show the names of employees who is assigned to ProjectID 1000 ***/ /* Q1. Find employee numbers who is assigned to projectID 1000 */ SELECT EmployeeNumber FROM ASSIGNMENT WHERE ProjectID = 1000; /* Q2. Show the names of employees with the employee numbers from Q1 */ SELECT FirstName, Lastname FROM EMPLOYEE WHERE EmployeeNumber IN (1,8,10); /* Use subquery to answer exercise 1 */ SELECT FirstName, Lastname FROM EMPLOYEE WHERE EmployeeNumber IN (SELECT EmployeeNumber FROM ASSIGNMENT WHERE ProjectID = 1000);

Exercise 1: use join Show the names of employees who is assigned to ProjectID 1000 IST2108 Shared column: EmployeeNumber

9 /* Use join to answer exercise 1 */ SELECT FirstName, Lastname FROM EMPLOYEE AS E, ASSIGNMENT AS A WHERE E.EmployeeNumber = A.EmployeeNumber AND A.ProjectID=1000;

Exercise 2 Show the project names assigned to EmployeeNumber 4 IST21010 ASSIGNMENT PROJECT

IST21011 /*** Exercise 2: Show the project names assigned to EmployeeNumber 4 ***/ /* Q1. ProjectIDs assigned to Employee Number 4 */ SELECT ProjectID FROM ASSIGNMENT WHERE EmployeeNumber = 4; /* Q2. Project names with project IDs from Q1 */ SELECT ProjectName FROM PROJECT WHERE ProjectID IN (1100, 1200, 1400); /* Use subquery to answer exercise 2 */ SELECT ProjectName FROM PROJECT WHERE ProjectID IN (SELECT ProjectID FROM ASSIGNMENT WHERE EmployeeNumber = 4);

Exercise 2: use join Show the project names assigned to EmployeeNumber 4 IST21012 Shared column: ProjectID

IST21013 /* Use join to answer exercise 2 */ SELECT ProjectName FROM PROJECT AS P, ASSIGNMENT AS A WHERE P.ProjectID = A.ProjectID AND A.EmployeeNumber=4;

Exercise 3 Show all the project names that are assigned to Ken – Write 3 separate queries first and then merge them into 1 IST21014 ASSIGNMENT PROJECT 3. Names of the projects with ID in (1000, 1300) 1. Employee numbers with first name as Ken: 10 EMPLOYEE 2. ProjectID assigned to employee number 10: 1000, 1300

IST21015 /* use subquery to answer exercise 3*/ SELECT ProjectName FROM PROJECT WHERE ProjectID IN (SELECT ProjectID FROM ASSIGNMENT WHERE EmployeeNumber IN (SELECT EmployeeNumber FROM EMPLOYEE WHERE FirstName = 'Ken' ) );

Exercise 3: Use Join Show all the project names that are assigned to Ken – Use join IST21016 Shared column: ProjectIDShared column: EmployeeNumber

IST21017 /* use join to answer exercise 3*/ SELECT ProjectName FROM EMPLOYEE AS E, PROJECT AS P, ASSIGNMENT AS A WHERE E.EmployeeNumber = A.EmployeeNumber AND P.ProjectID = A.ProjectID AND E.FirstName='Ken';