11 Processing Single Table 2-Ayu
11 Processing Single Table 2-Ayu
PROCESSING
SINGLE TABLE
Part 2
Maxmanroe.com
Learning Outcomes
Program Learning Outcomes (PLO)
PLO-9 Students are able to make decisions appropriately in the context of problem
solving, based on the results of the analysis of information / data and the
implications of decisions.
ORDER BY Clauses
GROUP BY Clauses
HAVING clause
PROCESSING
SINGLE TABLE
Part 2.1 Using Range for Qualification
Maxmanroe.com
PROCESSING
SINGLE TABLE
Part 2.2 Using Distinct Values
Maxmanroe.com
SELECT OrderID
FROM OrderLine_T;
11
PROCESSING
SINGLE TABLE
Part 2.3 Using IN and NOT IN in lists
Maxmanroe.com
PROCESSING
SINGLE TABLE
Part 2.4 ORDER BY Clauses
Maxmanroe.com
ORDER BY Clauses
• ‘ORDER BY’ Sorts the final results rows
SELECT ...
in ascending or descending order. FROM ...
• The default is ascending WHERE ...
ORDER BY A1 [ASC/DESC]
• If sorting from high to low, use DESC as
a keyword
17
ORDER BY Clauses
SELECT CustomerName, CustomerCity, CustomerState
FROM Customer_T
WHERE CustomerState IN (‘FL’, ‘TX’, ‘CA’, ‘HI’)
ORDER BY CustomerState, CustomerName;
18
ORDER BY Clauses
SELECT CustomerName, CustomerCity, CustomerState
FROM Customer_T
WHERE CustomerState IN (‘FL’, ‘TX’, ‘CA’, ‘HI’)
ORDER BY CustomerState, CustomerName;
19
ORDER BY Clauses
SELECT CustomerName, CustomerCity, CustomerState
FROM Customer_T
WHERE CustomerState IN (‘FL’, ‘TX’, ‘CA’, ‘HI’)
ORDER BY CustomerState, CustomerName;
? →
→
20
PROCESSING
SINGLE TABLE
Part 2.5 GROUP BY Clauses
Maxmanroe.com
GROUP BY Clauses
• GROUP BY is particularly useful when paired with aggregate
functions
• GROUP BY divides a table into subsets (by groups)
• An aggregate function can be used to provide summary information for that group.
• Scalar Aggregate
• A single value returned from an SQL query that includes an aggregate function.
• Vector Aggregate
• Multiple values returned from an SQL query that includes an aggregate function.
22
GROUP BY Clauses
• Count the number of customers with
addresses in each state to which we
ship.
PROCESSING
SINGLE TABLE
Part 2.6 HAVING clause
Maxmanroe.com
HAVING clause
• The HAVING clause acts like a WHERE clause, but it identifies
groups, rather than rows, that meet a criterion.
• Therefore, you will usually see a HAVING clause following a
GROUP BY clause.
25
HAVING Clauses
• Find only states with more than one
customer.
PROCESSING
SINGLE TABLE
Part 2.7 Example of Basic Queries
Maxmanroe.com
10/24/2015 OrderID
OrderDate
CustomerID
35
10/24/2015 OrderID
OrderDate
CustomerID
References
Hoffer, Jeffrey A., et.al., "Modern Database Management", Twelfth
Edition, Pearson, 2016. Chapter 6.
Recommended Link:
https://www.sqltutorial.org/
42
THANK
YOU