Querying Database ISYS 363.

Slides:



Advertisements
Similar presentations
Complex Conditions. Logical Operators: AND, OR, NOT AND Cond1Cond2Cond1 AND Cond2T TF FTF OR Cond1Cond2Cond1 OR Cond2T TF FTF NOT CondNOT Cond T F.
Advertisements

Relational Algebra, Join and QBE Yong Choi School of Business CSUB, Bakersfield.
Normalization ISYS 464. Database Design Based on ERD Strong entity: Create a table that includes all simple attributes –Composite Weak entity: add owner.
Tutorial 3 Queries and Table Relationships
SQL Sub (or Nested ) Query. Examples Q: Find students whose GPA is below the average. –The criteria itself requires a SQL statement. –SELECT * FROM student.
Concepts of Database Management Seventh Edition
Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
Database Features. Lists n An Excel worksheet can be used like a table in a relational database. n In Excel, such a table is called a list. n Each row.
The University of Akron Dept of Business Technology Computer Information Systems The Relational Model: Query-By-Example (QBE) 2440: 180 Database Concepts.
Data Modeling and Relational Database Design ISYS 650.
Querying Database ISYS 363. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy.
SQLPlus Commands. Oracle Account Server: libra.sfsu.edu Telnet: libra.sfsu.edu How to use Oracle: –
Structured Query Language Review ISYS 650. Language Overview Three major components: –Data definition language, DDL Create, Drop and Alter Tables or Views.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Data Modeling with ERD ISYS 363. Entity-Relationship Diagram An entity is a “thing” in the real world, such as a person, place, event for which we intend.
Querying a Database Using the Select Query Window
Introduction to Database. File Formats Comma delimited file –"s1","peter",3 –"s2","paul",2.5 –"s3","mary",3.5 –Demo: Excel – Data/Import Extended Markup.
Basic SQL Select Commands. Basic Relational Query Operations Selection Projection Natural Join Sorting Aggregation: Max, Min, Sum, Count, Avg –Total –Sub.
Querying Database ISYS 363. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy.
Introduction to Access BUS 782. Access Objects Tables –Open –Design –New –Wizard Queries Forms Reports Pages.
Structured Query Language Part I Chapter Three CIS 218.
Structured Query Language Chapter Three (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
Relational Algebra. Set operations: Union, intersection, difference, Cartesian product Relational operations: Selection, projection, join, division.
Chapter 2 Querying a Database
Querying Database. Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count –Totals and SubTotals –GroupBy Calculated.
Relational Operators, SQL, and Access Query ISYS 562.
Interpreting SQL Code. SQL (The language used to query a database) S is used to specify the you want to include. F is used to specify the the selected.
Microsoft Access 2010 Chapter 7 Using SQL.
Computer Science 101 Web Access to Databases SQL – Extended Form.
Exploring Office Grauer and Barber 1 Information From the Database: Reports and Queries(Wk4)
Concepts of Database Management, Fifth Edition
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
Database Applications – Microsoft Access Lesson 9 Designing Special Queries Updated 4/11.
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
Relational Query Operators (ii). Other Joins Theta join: Apply any specified condition on the product of two relations. Example: BoyStudent: BID, Bname,
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
Analyzing Data For Effective Decision Making Chapter 3.
Concepts of Database Management Seventh Edition
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) Structured Query Language Introduction to SQL Structured Query Language.
Advanced SQL for Decision Support ISYS 650. Set Operators Union Intersect Difference Cartesian product.
Using Special Operators (LIKE and IN)
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 - Information From the Database: Reports.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
MIS 3053 Database Design & Applications The University of Tulsa Professor: Akhilesh Bajaj RM/SQL Lecture 5 © Akhilesh Bajaj, 2000, 2002, 2003, All.
Chapter 3 Query and Report. Agenda Report types Report contents Report creation Report design view Query and dynaset Function and grouping Action query.
Introduction to Access ISYS 363. Creating a New Database MS Office button/New –Blank database –New database name and location.
Reports and Queries Chapter 3 – Access text Reports – Page Queries – Page
Relational Query Operators (Algebra). Relational Query Operators Set operations: Union, intersection, difference, Cartesian product Relational operations:
3 / 12 CHAPTER Databases MIS105 Week-10/ Lec02 Irfan Ahmed Ilyas.
Data Modeling with ERD BUS 782. Entities An entity is a person, place, object, event, or concept in the user environment about which the organization.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Introduction to Query Language and SQL. Basic Query Language Operators Selection Projection Join Aggregates –Sum, Count, Max, Min, Avg SubTotal Calculated.
Introduction to Access BUS 782. Creating a New Database MS Office button/New –Blank database –New database name and location.
Introduction to Access ISYS 363. Access Objects Tables –Open –Design –New –Wizard Queries Forms Reports Pages.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
Lesson 4: Querying a Database. 2 Learning Objectives After studying this lesson, you will be able to:  Create, save, and run select queries  Set query.
Introduction to Access ISYS 363. Access Objects Tables –Open a table: Double click the table name –Home/View: Datasheet view Design view Queries Forms.
Set Operators. Union Intersect Difference Cartesian product.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Data Modeling with ERD ISYS 363.
VOCAB REVIEW. A field that can be computed from other fields Calculated field Click for the answer Next Question.
Computer Science & Engineering 2111 Inner Joins and Advanced Queries 1CSE 2111 Lecture-Advanced Queries.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Querying Database ISYS 363.
Structured Query Language
File Processing with Excel’s List
Query Functions.
Shelly Cashman: Microsoft Access 2016
Chapter 3 Query and Report.
Presentation transcript:

Querying Database ISYS 363

Basic Query Language Operations Selection Projection Join Aggregates: Max, Min, Sum, Avg, Count Totals and SubTotals GroupBy Calculated fields

Selection Selection operation retrieves records that satisfy user’s criteria.

Criteria >, >=, <, <=, =, <> Range: BETWEEN 1/1/03 AND 12/31/03 Wildcard: ? – match any one character “K?NG” * - Match any number of characters “C*”

Projection Projection operation defines a vertical subset of a table and retrieves only the specified fields. Example: Customer table: CID, Cname, City, Rating Create a query to show CID, Cname, Rating Create a query to show CID, Cname, City

Join The two tables must have common attributes: Key and foreign key match. Combines two tables to form a new table where records of the two tables are combined if the common attributes have the same value.

Join Example Faculty File: FID Fname F1 Chao F2 Smith F5 Boxer Student File: SID Sname FID S1 Peter F1 S2 Paul F2 S3 Smith F1 Faculty Join Student =

Join Example (Student Join StudentCourse) Join Course StudentCourse File: SID CID S1 ISYS263 S1 Acct101 S3 ISYS363 S2 ISYS263 S2 Fin350 S2 Acct101 Student File: SID Sname FID S1 Peter F1 S2 Paul F2 S3 Smith F1 Course File: CID Cname Units ISYS263 IS Intro 3 ISYS363 MIS Intro 3 Acct101 accounting 3 Fin350 Finance Intro 3 (Student Join StudentCourse) Join Course

Aggregate Functions Max, Min, Sum, Count, Avg QueryTools/Totals Ex. Employee: EmpID,Ename, Sex, Race, Birthdate, Hiredate, Salary How many employees in this company? What is the overall average salary?

Aggregates by Group Compute the average salary by race. Compute the average salary by sex. Compute the average salary by Race and Sex. How many employees in each race group?

University Database

ERD Notations 1 1 Student Has Account M M M 1 Faculty Course Enroll Major Sname GPA SID Balance SID 1 1 Student Has Account M M M Enroll Advise Grade 1 Faculty Course Units Phone FID Fname CID Cname

Query Examples Q1: Display students’ ID, name and account balance who owe university more than $2000. Q2: Display student’s ID, name and total units. Q3: Find students taking at least 9 units and display their ID, Name and total units. Q4: Display CID, Cname, SID, Sname Q5: Display CID, Cname, number of students in each course. Q6: Display faculty’s name and phone if the faculty advises at least three students.

Order Processing Database

Query Examples Total sales by product Total amount for each order Find customers live in San Francisco. Produce a customer report that shows CID, Cname, and Rating. Number of customers in each city City, NumbeOfCustomers Produce a report that shows the number of orders for each customer: CID, Cname, TotalNumberOfOrders Total sales by product Total amount for each order MIS report Criteria applied to subtotal

Calculated Fields Rename a field: Define a calculated field: NewName:OldName Define a calculated field: Tax:salary*.15 Age:Year(Now()) – Year(DOB) IIF function

Sorting One field sorting Two fields sorting

Other Queries Update query: Delete query Parameter query Query tools/Design/Query type/Update Delete query Parameter query CrossTab query Crosstab row

Top n query: Example Top 3 GPA 1. Sort GPA in descending order 2 Top n query: Example Top 3 GPA 1. Sort GPA in descending order 2. From Query/Design view, click Property Sheet and select Top Value