Download presentation
Presentation is loading. Please wait.
Published byReynard Park Modified over 6 years ago
1
CSIS 115 Database Design and Applications for Business
Dr. Meg Fryling “Dr. Meg” Fall 2012 @SienaDrMeg #csis115
2
Agenda Questions? Assignments Review Chapter 2 - SQL Basics
“Fun” with iClicker Chapter 2 - SQL Basics Continued
3
Homework Project Part I Finish Chapter 3 (100-105 only)
Was due at the start of class today Finish Chapter 3 ( only) Finish Chapter 5 Reminder: Quiz 1 will be Mon, 9/24 Closed book but you may have a 8.5x11 handwritten “cheat sheet”. Must use your own and turn in with quiz.
4
Let’s do some review from last week
Get those clickers ready!
5
The industry standard supported by all major DBMS that allows data to be selected, added, updated, and deleted from a relational database is… A) Sequential Query Language (SQL) B) Structured Question Language (SQL) C) Structured Query Language (SQL) D) Relational Question Language (RQL) E) Relational Query Language (RQL)
6
Which elements are required in an SQL statement
SELECT FROM WHERE SELECT and FROM SELECT, FROM, and WHERE Answer: D
7
In addition to being a data sublanguage, SQL is also a programming language, like Java or C#
A) True B) False Answer: FALSE KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
8
The SQL keyword SELECT is used to specify the __________ to be listed in the query results.
A) Columns B) Rows C) Records D) Tuples E) None of the above Answer: A KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
9
A column is also referred to as a field or an attribute
A) True B) False Answer: A KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
10
Add ORDER BY Update the query below so it sorts the records by OrderNumber and then by Price SELECT * FROM ORDER_ITEM ORDER BY OrderNumber; Last time we ended with this query
11
Sorting the Results – ORDER BY
SELECT * FROM ORDER_ITEM ORDER BY OrderNumber, Price; KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
12
Which order are the results sorting in? Ascending Descending
Sort Order Default Which order are the results sorting in? Ascending Descending Answer: A
13
Sort Order: Ascending and Descending
SELECT * FROM ORDER_ITEM ORDER BY Price DESC, OrderNumber ASC; NOTE: The default sort order is ASC – does not have to be specified. KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
14
SQL for Data Retrieval: Logical Operators
Multiple matching criteria (conditions) may be specified using… AND Representing an intersection of the data sets OR Representing a union of the data sets
15
Write a Query Selects all columns from the SKU_DATA table
Only include rows for the Water Sports department where the buyer is Nancy Meyers
16
WHERE Clause Options - AND
SELECT * FROM SKU_DATA WHERE Department = 'Water Sports' AND Buyer = 'Nancy Meyers'; KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
17
Write a Query Selects all columns from the SKU_DATA table
Only include rows that are associated with the Camping or the Climbing department
18
WHERE Clause Options - OR
SELECT * FROM SKU_DATA WHERE Department = 'Camping' OR Department = 'Climbing'; KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
19
How many rows will this query return?
SELECT * FROM SKU_DATA WHERE Department = 'Water Sports' AND Buyer = 'Nancy Meyers'; Answer: 2 Just look at data in SKU_DATA table first to answer this question?
20
How many rows will this query return?
SELECT * FROM SKU_DATA WHERE Department = 'Camping' OR Department = 'Climbing'; Answer: 4 Just look at data in SKU_DATA table first to answer this question?
21
Write a Query That will return all columns from the ORDER_ITEM table
Only include records with an extended price greater than or equal to 100 and less than or equal to 200 Only include records for SKU or SKU Hint: You will need to use both AND and OR in the WHERE clause
22
Using both OR and AND SELECT * FROM ORDER_ITEM
WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND SKU = OR SKU = ; Does this return what you would expect?
23
Remember operator precedence?
3 + 4 × 5 = 23 vs (3 + 4) × 5 = 35 KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
24
Excel OR() and AND() Functions
Recall CSIS114 BI-OLAP Lab =IF(OR(A3<62,C3="snow",C3="rain",B3>70%,AND(D3="Monday",OR(E4="Average",E4="Bad"))),"no","yes")
25
Using both OR and AND SELECT * FROM ORDER_ITEM
WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND SKU = OR SKU = ; How do you think you can “fix” this query?
26
Using both OR and AND SELECT * FROM ORDER_ITEM WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND (SKU = OR SKU = );
27
Gotcha When using both OR & AND clauses be sure to use () to clarify what criteria belongs together If not you may get unexpected results! KROENKE AND AUER - DATABASE PROCESSING, 11th Edition © 2010 Pearson Prentice Hall
28
SQL for Data Retrieval: Inclusion/Exclusion
SQL provides a IN/NOT IN statements that allows a user to specify all valid values on one line! SWEET SELECT FieldName FROM TABLE WHERE FieldName IN (X,Y,Z); SELECT FieldName FROM TABLE WHERE FieldName = X OR FieldName = Y OR FieldName = Z; You can use this instead of _______________
29
SQL for Data Retrieval: The Logical NOT Operator
Any criteria statement may be preceded by a NOT operator which is to say that all information will be shown except that information matching the specified criteria SELECT FieldName FROM TABLE WHERE FieldName NOT IN (X, Y, Z);
30
WHERE Clause Options - IN
Update query below so it uses IN clause to return same results SELECT * FROM ORDER_ITEM WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND (SKU = OR SKU = );
31
WHERE Clause Options - IN
SELECT * FROM ORDER_ITEM WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND SKU IN(101100, ); Wow, that sure looks cleaner! What if we wanted to return all SKU records that were NOT or but had an extended price between 100 and 200?
32
WHERE Clause Options – NOT IN
SELECT * FROM ORDER_ITEM WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND SKU NOT IN(101100, );
33
SQL for Data Retrieval: Finding Data in a Range of Values
SQL provides a BETWEEN statement that allows a user to specify a minimum and maximum value on one line! SUPER SWEET Note: Will include the minimum and maximum value in the results SELECT FieldName FROM TABLE WHERE FieldName BETWEEN X AND Y;
34
SQL for Data Retrieval: Finding Data in a Range of Values
Update query below so it uses BETWEEN clause to return same results SELECT * FROM ORDER_ITEM WHERE ExtendedPrice >= 100 AND ExtendedPrice <= 200 AND SKU IN(101100, );
35
WHERE Clause Options – BETWEEN
SELECT * FROM ORDER_ITEM WHERE ExtendedPrice BETWEEN 100 AND 200 AND SKU IN(101100, ); Huh, that’s awesome!
36
In-Class Activity Part III
SQL Basics In-Class Activity Part III
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.