Professional Documents
Culture Documents
(It) 09 Processing Single Table 1
(It) 09 Processing Single Table 1
PROCESSIN
G SINGLE
TABLE Part 1
Maxmanroe.com
Learning Outcomes
Students are able to use basic query to get information
3
SELECT Statement
Arithmetic Expressions
Using functions
PROCESSIN
G SINGLE
TABLE
Part 1.1 SELECT Statement
Maxmanroe.com
SELECT Statement
• Query is a statement in SQL to retrieve data from a database
• The output of a query is a relation
• Basic query
6
SELECT Statement
• Query is a statement in SQL to retrieve data from a database
• The output of a query is a relation
• Basic query
7
SELECT Statement
• Query is a statement in SQL to retrieve data from a database
• The output of a query is a relation
• Basic query
8
SELECT Statement
• Query is a statement in SQL to retrieve data from a database
• The output of a query is a relation
• Basic query
9
SELECT Statement
• List of products and its standard price
SELECT Statement
• Which products have a standard price of less than $275?
PROCESSIN
G SINGLE
TABLE
Part 1.2 Arithmetic Expressions
Maxmanroe.com
Arithmetic Expressions
• Adding expressions to the basic + Addition
Arithmetic Expressions
• What are the standard price and standard price if increased by 10
percent for every product?
Arithmetic Expressions
• Note! + Addition
• Multiplication and division take precedence over addition and - Subtraction
subtraction
* Multiplication
• Operators with the same priority will be executed from the
leftmost operator / Division
• The brackets '()' are used to indicate that the statement inside must
be executed first.
15
PROCESSIN
G SINGLE
TABLE
Part 1.3 Using Functions
Maxmanroe.com
Using Functions
• Standard SQL identifies a wide variety of functions.
Mathematical MIN, MAX, COUNT, SUM, AVERAGE, ROUND, TRUNC, and MOD
String LOWER, UPPER, INITCAP, CONCAT, SUBSTR, and COALESCE
Date NEXT_DAY, ADD_ MONTHS, and MONTHS_BETWEEN
17
Using Functions
• What is the average standard price for all products in inventory?
Using Functions
• How many different items were ordered on order number 1004?
PROCESSIN
G SINGLE
TABLE
Part 1.4 Wildcards (*)
Maxmanroe.com
Wildcards
used as a wildcard to indicate all columns, displays all columns
* from all the items in the FROM clause
used to represent any collection of characters
%
used as a wildcard character to represent exactly one character
_ rather than any collection of characters
21
Wildcards
SELECT *
FROM OrderLine_T
WHERE OrderID = 1004;
Wildcards
SELECT *
FROM Product_T
WHERE ProductDescription like ‘%desk’;
Wildcards
SELECT *
FROM Product_T
WHERE ProductName like ‘_-drawer’;
PROCESSIN
G SINGLE
TABLE
Part 1.5 Using Comparison Operators
Maxmanroe.com
PROCESSIN
G SINGLE
TABLE
Part 1.6 Null Values
Maxmanroe.com
Null Values
• A null value means that a column is missing a value; the value is
not zero or blank or any special code—there simply is no value
30
Null Values
ProductDescription ProductStandardPrice AVERAGE(ProductStandardPrice) = 375
Computer Desk 375
Writer’s Desk Cherry 0
8-Drawer Desk 750
Null Values
• Display all customers for whom we do not know their postal code
SELECT *
FROM Customer_T
WHERE CustomerPostalCode IS NULL;
32
Null Values
• Display all customers data whose postal code is not NULL
SELECT *
FROM Customer_T
WHERE CustomerPostalCode IS NOT NULL;
33
PROCESSIN
G SINGLE
TABLE
Part 1.7 Boolean Operators
Maxmanroe.com
Boolean Operators
• AND Joins two or more conditions and returns results only when
all conditions are true.
• OR Joins two or more conditions and returns results when any
conditions are true.
• NOT Negates an expression.
35
Boolean Operators
• If multiple Boolean operators are used in an SQL statement, NOT
is evaluated first, then AND, then OR.
36
Boolean Operators
• List product name, finish, and standard price for all desks and all
tables that cost more than $300 in the Product table.
SELECT ProductDescription, ProductFinish, ProductStandardPrice
FROM Product_T
WHERE ProductDescription LIKE ‘%Desk’ OR ProductDescription LIKE ‘%Table’
AND ProductStandardPrice > 300;
<300 ?
37
Boolean Operators
...
WHERE
ProductDescription LIKE ‘%Desk’
OR
ProductDescription LIKE ‘%Table’
AND
ProductStandardPrice > 300;
38
Boolean Operators
• List product name, finish, and standard price for all desks and all
tables that cost more than $300 in the Product table.
SELECT ProductDescription, ProductFinish, ProductStandardPrice
FROM Product_T
WHERE (ProductDescription LIKE ‘%Desk’ OR ProductDescription LIKE ‘%Table’)
AND ProductStandardPrice > 300;
√
39
Boolean Operators
...
WHERE
(ProductDescription LIKE ‘%Desk’
OR
ProductDescription LIKE ‘%Table’ )
AND
ProductStandardPrice > 300;
40
References
Hoffer, Jeffrey A., et.al., "Modern Database Management", Twelfth
Edition, Pearson, 2016. Chapter 6.
Recommended Link:
https://www.w3schools.com/sql/
41
THANK
YOU