Information Retrieval from Relational Databases

Slides:



Advertisements
Similar presentations
Request Dispatching for Cheap Energy Prices in Cloud Data Centers
Advertisements

SpringerLink Training Kit
Luminosity measurements at Hadron Colliders
From Word Embeddings To Document Distances
Choosing a Dental Plan Student Name
Virtual Environments and Computer Graphics
Chương 1: CÁC PHƯƠNG THỨC GIAO DỊCH TRÊN THỊ TRƯỜNG THẾ GIỚI
THỰC TIỄN KINH DOANH TRONG CỘNG ĐỒNG KINH TẾ ASEAN –
D. Phát triển thương hiệu
NHỮNG VẤN ĐỀ NỔI BẬT CỦA NỀN KINH TẾ VIỆT NAM GIAI ĐOẠN
Điều trị chống huyết khối trong tai biến mạch máu não
BÖnh Parkinson PGS.TS.BS NGUYỄN TRỌNG HƯNG BỆNH VIỆN LÃO KHOA TRUNG ƯƠNG TRƯỜNG ĐẠI HỌC Y HÀ NỘI Bác Ninh 2013.
Nasal Cannula X particulate mask
Evolving Architecture for Beyond the Standard Model
HF NOISE FILTERS PERFORMANCE
Electronics for Pedestrians – Passive Components –
Parameterization of Tabulated BRDFs Ian Mallett (me), Cem Yuksel
L-Systems and Affine Transformations
CMSC423: Bioinformatic Algorithms, Databases and Tools
Some aspect concerning the LMDZ dynamical core and its use
Bayesian Confidence Limits and Intervals
实习总结 (Internship Summary)
Current State of Japanese Economy under Negative Interest Rate and Proposed Remedies Naoyuki Yoshino Dean Asian Development Bank Institute Professor Emeritus,
Front End Electronics for SOI Monolithic Pixel Sensor
Face Recognition Monday, February 1, 2016.
Solving Rubik's Cube By: Etai Nativ.
CS284 Paper Presentation Arpad Kovacs
انتقال حرارت 2 خانم خسرویار.
Summer Student Program First results
Theoretical Results on Neutrinos
HERMESでのHard Exclusive生成過程による 核子内クォーク全角運動量についての研究
Wavelet Coherence & Cross-Wavelet Transform
yaSpMV: Yet Another SpMV Framework on GPUs
Creating Synthetic Microdata for Higher Educational Use in Japan: Reproduction of Distribution Type based on the Descriptive Statistics Kiyomi Shirakawa.
MOCLA02 Design of a Compact L-­band Transverse Deflecting Cavity with Arbitrary Polarizations for the SACLA Injector Sep. 14th, 2015 H. Maesaka, T. Asaka,
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Fuel cell development program for electric vehicle
Overview of TST-2 Experiment
Optomechanics with atoms
داده کاوی سئوالات نمونه
Inter-system biases estimation in multi-GNSS relative positioning with GPS and Galileo Cecile Deprez and Rene Warnant University of Liege, Belgium  
ლექცია 4 - ფული და ინფლაცია
10. predavanje Novac i financijski sustav
Wissenschaftliche Aussprache zur Dissertation
FLUORECENCE MICROSCOPY SUPERRESOLUTION BLINK MICROSCOPY ON THE BASIS OF ENGINEERED DARK STATES* *Christian Steinhauer, Carsten Forthmann, Jan Vogelsang,
Particle acceleration during the gamma-ray flares of the Crab Nebular
Interpretations of the Derivative Gottfried Wilhelm Leibniz
Advisor: Chiuyuan Chen Student: Shao-Chun Lin
Widow Rockfish Assessment
SiW-ECAL Beam Test 2015 Kick-Off meeting
On Robust Neighbor Discovery in Mobile Wireless Networks
Chapter 6 并发:死锁和饥饿 Operating Systems: Internals and Design Principles
You NEED your book!!! Frequency Distribution
Y V =0 a V =V0 x b b V =0 z
Fairness-oriented Scheduling Support for Multicore Systems
Climate-Energy-Policy Interaction
Hui Wang†*, Canturk Isci‡, Lavanya Subramanian*,
Ch48 Statistics by Chtan FYHSKulai
The ABCD matrix for parabolic reflectors and its application to astigmatism free four-mirror cavities.
Measure Twice and Cut Once: Robust Dynamic Voltage Scaling for FPGAs
Online Learning: An Introduction
Factor Based Index of Systemic Stress (FISS)
What is Chemistry? Chemistry is: the study of matter & the changes it undergoes Composition Structure Properties Energy changes.
THE BERRY PHASE OF A BOGOLIUBOV QUASIPARTICLE IN AN ABRIKOSOV VORTEX*
Quantum-classical transition in optical twin beams and experimental applications to quantum metrology Ivano Ruo-Berchera Frascati.
The Toroidal Sporadic Source: Understanding Temporal Variations
FW 3.4: More Circle Practice
ارائه یک روش حل مبتنی بر استراتژی های تکاملی گروه بندی برای حل مسئله بسته بندی اقلام در ظروف
Decision Procedures Christoph M. Wintersteiger 9/11/2017 3:14 PM
Limits on Anomalous WWγ and WWZ Couplings from DØ
Presentation transcript:

Information Retrieval from Relational Databases Chapter 7 Information Retrieval from Relational Databases

Chapter Learning Objectives Identify and explain the purpose of the three primary relational algebra operators Identify and explain the primary components of a Structured Query Language (SQL) statement Identify the relational algebra operations achieved by a given SQL statement Create a SQL statement to retrieve requested information from a relational database Examine a SQL statement and the tables to which it will be applied and identify the query result Find errors in a SQL statement Create a Microsoft Query-by-Example (QBE) to retrieve information from relational tables Examine a Microsoft Access QBE query and the tables to which it applies and identify the query result Find errors in a Microsoft Access QBE query

Examples of Needs for Multiple Views of One Data Set Cash-basis versus Accrual Accounting Weighted Average versus FIFO or LIFO Double-Declining Balance Depreciation versus Straight Line Foreign Currency Translation How do we get these multiple views???????

Answer: Query the Data Set What is Querying? It is asking questions about the data in the database and manipulating or combining the data in different ways We can isolate certain rows in tables, we can isolate certain columns in tables, we can join tables together, we can create calculations based on various data items, etc.

Querying/Information Retrieval Several ingredients are necessary for effective querying A database that is well-designed If tables are not fully relational or incompletely specified, or if conceptual model has not been correctly converted into relational form, querying will be difficult or impossible A query developer who understands the table structures and the nature of the data in the tables A query developer who understands the desired query output A query developer who has good logic and reasoning skills A query developer who knows the querying language used to retrieve information from the enterprise database

Three Query Languages Relational Algebra Three main operators: Select, Project, Join Provides the conceptual basis for SQL and QBE Structured Query Language (SQL) The user enters commands according to a pre-defined syntax to retrieve desired data. Query By Example (QBE) The user starts with a sample of the table(s) columns and marks the fields he or she wants to include in the answer. Defaults are available for summarizing and manipulating the data.

Relational Algebra Select Project Join includes only certain rows from a database table in its “answer”. Project includes only certain columns from a database table in its “answer” Join combines two or more database tables on the basis of one or more common attributes

Example Tables (Incomplete Enterprise Database) from Dunn & McCarthy (2004) working paper

Relational Algebra SELECT Find the cash receipts from Customer #2 (keeping all the details of those cash receipts) Select Cash Receipt Where Customer Number = C-2 Giving Answer Examination of the Customer and Cash Receipt tables reveals that only the cash receipt table is needed for the required information retrieval. Because all columns are to be included, but only the rows pertaining to C-2, the operator needed is a Select.

Relational Algebra PROJECT Find the customer number, name, and salesperson number for all customers Project Customer Over (Customer#, Name, SP#) Giving Answer Examination of the customer and salesperson tables reveals that only the customer table is needed to retrieve the required information. Because all rows are to be included in the answer, but not all the columns, the operator needed is a Project.

Join Types Inner join Outer join includes only the records from both tables that have the exact same values in the fields that are joined I.e., Outer join includes all records from one table, and matches those records from the other table for which values in the joined fields are equal Left Outer Join Right Outer Join

Relational Algebra Inner Join Find all details of all customers and all available details of each customer’s salesperson Join Customer, Salesperson Where Customer.SP# = [Salesperson.Employee Number] Giving Answer Examination of the customer and salesperson tables reveals that both are needed to provide all the required information. The joining point is on the salesperson number (which is called employee number in the salesperson table). Because all salesperson numbers in the customer table are expected to have exact matches in the salesperson table and because we are not interested in salespeople who have not yet been assigned to customers, an inner join is the appropriate join type.

Relational Algebra Left Outer Join Find all details of all sales and the cash receipt number and amount applied of any cash receipts related to those sales Left Outer Join Sale, [Sale - CashRecDuality] Where [Sale.Sale#] = [Sale - CashRecDuality.Sale#] Giving Answer Examination of the Sale, Cash Receipt, and Sale-CashRecDuality tables reveals that only the Sale and Sale-CashRecDuality tables are needed for the required information retrieval. Because we want to include all details of all sales (whether or not cash has been received for them) we need a left outer join.

SQL (Structured Query Language) Each query statement follows the same structure: SELECT attribute name(s) FROM table name(s) WHERE criteria is met;

SQL Statements and Relational Algebra SQL’s SELECT component isolates columns i.e., relational algebra’s project SQL’s FROM component is used for identifying the table(s) involved if >1 table, helps accomplish relational algebra’s join (together with WHERE component that specifies equal fields) SQL’s WHERE component isolates rows i.e., relational algebra’s select also helps accomplish relational algebra’s join may be left blank for single-table queries that retrieve all rows

SQL and Relational Algebra SELECT Find the cash receipts from Customer #2 (keeping all the details of those cash receipts) Select * From [Cash Receipt] Where [Customer Number] = C-2; (note: the brackets are needed because of spaces in the table and field names; also note * is a wild card indicating all columns should be included) This is the same example as we used for the relational algebra select and are now creating the SQL statement that will result in the same answer. Notice the relational algebra SELECT operation is accomplished in the WHERE clause of the SQL statement.

SQL and Relational Algebra PROJECT Find the customer number, name, and salesperson number for all customers Select Customer#, Name, SP# From Customer; Now we examine the same example for which we previously performed a relational algebra project. The equivalent SQL statement and query result are shown. Notice the relational algebra PROJECT operation is accomplished in the SELECT clause of the SQL statement.

SQL and Relational Algebra Inner Join Find all details of all customers and all available details of each customer’s salesperson Select * From Customer, Salesperson Where Customer.SP# = [Salesperson.Employee Number]; We examine here the same example for which we previously needed an Inner Join of Customer and Salesperson. The equivalent SQL statement and query result are shown. Notice that the Inner Join is accomplished in the FROM and WHERE clauses of the SQL statement.

SQL and Relational Algebra Outer Join Find all details of all sales and the cash receipt number and amount applied of any cash receipts related to those sales Select * From Sale LeftJoin [Sale-CashRecDuality] Where [Sale.Sale#]=[Sale-CashRecDuality.Sale#]; We examine here the same example for which we previously needed a Left Outer Join of Sale and Sale-CashRecDuality. The equivalent SQL statement and query result are shown. Notice that the Left Outer Join is accomplished in the FROM and WHERE clauses of the SQL statement.

Mathematical Comparison Operators SQL Queries may include mathematical comparison operators such as = equal to < less than <= less than or equal to > greater than >= greater than or equal to <> not equal to (or != in some software) Mathematical comparison operators are typically included in the WHERE clause of the SQL statement, and may be used on all types of fields For date fields, dates that are earlier in time are “less than” dates that are later in time. For text fields, A < B < C, etc.

SQL Mathematical Comparison Operators Select Account#, Balance From Cash Where Balance>=50000;

SQL Mathematical Comparison Operators on Character Attributes Select Sale#, Amount From Sale Where SalesRep# <> E-10;

Queries with Logical Operators Queries may include logical operators AND, OR, and NOT AND accomplishes a set intersection – answer includes all instances that meet BOTH conditions OR accomplishes a set union – answer includes all instances that meet one condition and all instances that meet the other condition NOT identifies instances that do not meet one or more conditions

Queries with Special Operators BETWEEN is used to define the range limits. The end points of the range are included Select Sale#, Amount, Date From Sale Where Date BETWEEN 7/1 and 7/31; 31

Queries with Special Operators IS NULL is used to retrieve attributes for which the value is null. Select * From Cash Where Balance IS NULL; 32

Queries with Special Operators EXISTS is used to retrieve attributes for which the value is not null. Select * From Cash Where Balance EXISTS;

Aggregation Functions in Queries An aggregation function summarizes the data values within a field (column) COUNT summarizes the number of rows that contain a given value in the field AVERAGE computes the arithmetic mean value of all rows included in the answer SUM computes the arithmetic sum of all rows included in the answer MIN identifies the minimum (lowest) attribute value for the field MAX identifies the maximum (greatest) attribute value for the field

Queries with Horizontal Calculations “Horizontal” calculations mathematically combine values from different fields for each row Horizontal calculations should NOT be included in the same query as an aggregation function One query may perform a horizontal calculation and another query that builds on the first query may perform the aggregation function, or vice versa The “correct” order for the queries depends on the goal

Relational Algebra SELECT in QBE Cash Receipts from Customer C-2

Relational Algebra “Select” QBE Example: Cash Receipts from Customer C-2

Relational Algebra SELECT in QBE Cash Receipts from Customer C-2

Relational Algebra SELECT in QBE Cash Receipts from Customer C-2 Enter =“C-2” as Criteria in the Customer Number field

Relational Algebra SELECT in QBE Cash Receipts from Customer C-2 Result

Relational Algebra PROJECT in QBE Customer#, name, salesperson#

Relational Algebra PROJECT in QBE Customer#, name, salesperson#

Relational Algebra PROJECT in QBE Customer#, name, salesperson#

Relational Algebra PROJECT in QBE Customer#, name, salesperson# Result

Relational Algebra Inner Join in QBE: All details of customers and their salespeople

Relational Algebra Inner Join in QBE: All details of customers and their salespeople

Relational Algebra Inner Join in QBE: All details of customers and their salespeople

Relational Algebra Inner Join in QBE: All details of customers and their salespeople Result

Relational Algebra Outer Join in QBE Details of all sales, related cash receipts

Relational Algebra Outer Join in QBE Details of all sales, related cash receipts Double-click on the join line

Relational Algebra Outer Join in QBE Details of all sales, related cash receipts Click OK Click on appropriate join type

Relational Algebra Outer Join in QBE Details of all sales, related cash receipts Notice change in join line

Relational Algebra Outer Join in QBE Details of all sales, related cash receipts

Relational Algebra Outer Join in QBE Details of all sales, related cash receipts Result

QBE with Mathematical Comparison Operator Cash Account# and Balances >=$50,000

QBE with Mathematical Comparison Operator Cash Account# and Balances >=$50,000

QBE with Mathematical Comparison Operator Cash Account# and Balances >=$50,000 Result

QBE with Mathematical Comparison on Character Attribute: Sales Not made by E-10

QBE with Mathematical Comparison on Character Attribute: Sales Not made by E-10

QBE with Mathematical Comparison on Character Attribute: Sales Not made by E-10 Result

AND operator in QBE: Sales made before July 31 by Sales Rep E-10

AND operator in QBE: Sales made before July 31 by Sales Rep E-10

AND operator in QBE: Sales made before July 31 by Sales Rep E-10 Enter selection criteria on same line to accomplish logical “AND”

AND operator in QBE: Sales made before July 31 by Sales Rep E-10 Result

OR operator in QBE: Sales made before July 31 OR by Sales Rep E-10

OR operator in QBE: Sales made before July 31 OR by Sales Rep E-10

OR operator in QBE: Sales made before July 31 OR by Sales Rep E-10 Enter selection criteria on separate lines to accomplish logical “OR”

OR operator in QBE: Sales made before July 31 OR by Sales Rep E-10 Result

Aggregation SUM and Special Operator BETWEEN in QBE: Total Sales between July 15 and July 31

Aggregation SUM and Special Operator BETWEEN in QBE: Total Sales between July 15 and July 31 Bring only the fields you need into the query grid

Aggregation SUM and Special Operator BETWEEN in QBE: Total Sales between July 15 and July 31 Click on summation symbol to add “Total” line to query grid (used for aggregations) Enter Criteria with BETWEEN operator

Aggregation SUM and Special Operator BETWEEN in QBE: Total Sales between July 15 and July 31 Total line defaults to “Group By” for each field; Change the Amount field to “Sum” and change the Date field to “Where”

Aggregation SUM and Special Operator BETWEEN in QBE: Total Sales between July 15 and July 31

Aggregation SUM and Special Operator BETWEEN in QBE: Total Sales between July 15 and July 31 Result

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension Save query so that fields will be available to the Expression Builder; then click on the magic wand to start the Expression Builder

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension

Horizontal Calculation in QBE: Inventory-Sale Line Item Extension Result

Querying Summary Querying provides the power of the relational database model Once you unlock the mystery of query construction, you can tap into the wealth of information that is at your fingertips in a well-designed relational database Querying requires organized thinking and logic You must understand the structure of the database tables and the nature of the data in those tables. You must identify which table(s) are needed for each query, and determine the appropriate manipulations that need to be made in the appropriate sequence Some people find it helpful to organize their thinking by considering what relational algebra operators are needed even though the relational algebra language is rarely used Manually calculating the query result using a representative data sample is also very helpful for identifying query errors Remember to separate horizontal calculations from vertical aggregations Comprehensive testing of queries is crucial before releasing queries for use by general users

Chapter 7 End of Chapter