Download Chapter 7 - Websupport1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
7
The Database Model (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
1
7
Selecting Rows with
Conditional Restrictions
• Select partial table contents by placing
restrictions on rows to be included in output
– Add conditional restrictions to SELECT
statement, using WHERE clause
• Syntax:
– SELECT columnlist
FROM tablelist
[ WHERE conditionlist ] ;
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
2
7
Selecting Rows with
Conditional Restrictions (continued)
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE
FROM PRODUCT
WEHRE V_CODE = 21344
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
3
Selecting Rows with
Conditional Restrictions (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
7
4
7
Selecting Rows with
Conditional Restrictions (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
5
Selecting Rows with
Conditional Restrictions (continued)
7
SELECT P_DESCRIPT, P_INDATE, P_PRICE, V_CODE
FROM PRODUCT
WEHRE V_CODE <> 21344
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
6
7
Selecting Rows with
Conditional Restrictions (continued)
SELECT P_DESCRIPT, P_QOH, P_MIN, P_PRICE
FROM PRODUCT
WEHRE P_PRICE <=10
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
7
7
Selecting Rows with
Conditional Restrictions (continued)
SELECT P_DESCRIPT, P_QOH, P_MIN, P_PRICE
FROM PRODUCT
WEHRE P_CODE <= “1558-QW1”
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
8
Selecting Rows with
Conditional Restrictions (continued)
7
SELECT P_DESCRIPT,
P_QOH, P_PRICE,
P_QOH*P_PRICE
FROM PRODUCT
WEHRE P_CODE <= “1558QW1”
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
9
Selecting Rows with
Conditional Restrictions (continued)
7
SELECT P_DESCRIPT, P_QOH,
P_PRICE, P_QOH*P_PRICE as
TOTVALUE
FROM PRODUCT
WEHRE P_CODE <= “1558-QW1”
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
10
7
Arithmetic Operators:
The Rule of Precedence
• Perform operations within parentheses
• Perform power operations
• Perform multiplications and divisions
• Perform additions and subtractions
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
11
7
Arithmetic Operators:
The Rule of Precedence (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
12
7
Logical Operators:
AND, OR, and NOT
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
13
7
Logical Operators:
AND, OR, and NOT (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
14
7
Logical Operators:
AND, OR, and NOT (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
15
7
Special Operators
• BETWEEN
– Used to check whether attribute value is within
a range
• IS NULL
– Used to check whether attribute value is null
• LIKE
– Used to check whether attribute value
matches given string pattern
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
16
7
Special Operators (continued)
• IN
– Used to check whether attribute value
matches any value within a value list
• EXISTS
– Used to check if subquery returns any rows
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
17
7
Advanced Select Queries
• SQL provides useful functions that can:
– Count
– Find minimum and maximum values
– Calculate averages
• SQL allows user to limit queries to only those
entries having no duplicates or entries whose
duplicates may be grouped
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
18
7
Ordering a Listing
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
19
7
Ordering a Listing (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
20
7
Listing Unique Values
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
21
7
Aggregate Functions
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
22
7
Aggregate Functions (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
23
7
Aggregate Functions (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
24
7
Aggregate Functions (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
25
7
Aggregate Functions (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
26
7
Grouping Data
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
27
7
Grouping Data (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
28
7
Grouping Data (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
29
7
Joining Database Tables
• Ability to combine (join) tables on common
attributes is most important distinction
between relational database and other
databases
• Join is performed when data are retrieved
from more than one table at a time
• Join is generally composed of an equality
comparison between foreign key and primary
key of related tables
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
30
7
Joining Database Tables (continued)
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
31
Joining Database Tables (continued)
7
Select P_Descript,P_Price,V_Name,V_Contact,
V_Areacode, V_Phone
From Product, Vendor
Where Product.Vcode = Vendor.Vcode
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
32
7
Joining Tables with an Alias
• Alias can be used to identify source table
• Any legal table name can be used as alias
• Add alias after table name in FROM clause
– FROM tablename alias
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
33
Outer Joins
7
Select P_CODE, V_CODE, V_NAME
From Vendor LEFT JOIN Product
Where Product.Vcode = Vendor.Vcode
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
34
7
Outer Joins (continued)
Select P_CODE, V_CODE, V_NAME
From Vendor Right Join Product
Where Product.Vcode = Vendor.Vcode
Database Systems: Design, Implementation, & Management, 7th Edition, Rob & Coronel
35
Related documents