Subsetting Rows with the WHERE clause

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
IF statement (i) Single statement. IF ( logical expression ) statement Example: read(*,*) a if (a. lt. 0) a = -a write(*,*) a Or read(*,*) a if (a < 0)
Comparators Combinational Design.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Introduction to SQL Session 2 Retrieving Data From Multiple Tables.
Restricting and Sorting Data. Consider the table employee(employee_id,last_name,job_id, department_id ) assume that you want to display all the employees.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
1.2 – Open Sentences and Graphs
Queries and SQL in Access Please use speaker notes for additional information!
Ceng 356-Lab2. Objectives After completing this lesson, you should be able to do the following: Limit the rows that are retrieved by a query Sort the.
Objectives After completing this lesson, you should be able to do the following: Define subqueries Describe the types of problems that the subqueries.
IFS Intro. to Data Management Chapter 6 Filtering your data.
11 Chapter 2: Basic Queries 2.1: Overview of the SQL Procedure 2.2: Specifying Columns 2.3: Specifying Rows.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
LECTURE 8.  Consider the table employee(employee_id,last_name,job_id, department_id )  assume that you want to display all the employees in department.
Shell Programming. Creating Shell Scripts: Some Basic Principles A script name is arbitrary. Choose names that make it easy to quickly identify file function.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
Oracle 11g DATABASE DEVELOPMENT LAB2. Chapter- 2  These commands, which could be issued from SQL*Plus or SQL Developer,  will make it possible to log.
SAS for Data Management and Analysis
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
Subqueries.
OPERATORS Chapter2:part2. Operators Operators are special symbols used for: mathematical functions assignment statements logical comparisons Examples.
Shell script – part 2 CS 302. Special shell variable $0.. $9  Positional parameters or command line arguments  For example, a script myscript take 2.
11 Chapter 4: Subqueries 4.1: Noncorrelated Subqueries 4.2: Correlated Subqueries (Self-Study)
1 Lecture 8 Shell Programming – Control Constructs COP 3353 Introduction to UNIX.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Using Subqueries to Solve Queries
Chapter 6: Set Operators
Writing Basic SQL SELECT Statements
Chapter 1 Introduction.
Comparison Operators Relational Operators.
Basic Queries Specifying Columns
PROC SQL, Overview.
Noncorrelated subquery
Correlated Subqueries
Control Structures: if Conditional
Chapter 1 Introduction.
Restricting and Sorting Data
A more complex example.
Displaying Queries 2 Display a query’s results in a specified order.
Control Structures: for & while Loops
Outer Joins Inner joins returned only matching rows. When you join tables, you might want to include nonmatching rows as well as matching rows.
Grouping Summary Results
MongoDB Read/Write.
MongoDB Read/Write.
Using Subqueries to Solve Queries
Summarizing Data with Summary Functions
MongoDB Read/Write.
5 The EXCEPT Operator Unique rows from the first result set that are not found in the second result set are selected.
Using CASE Value expression
Chapter 1 Introduction.
Chapter 1 Introduction.
3 Specifying Rows.
MongoDB Read.
3 Views.
Presented by, Mr. Satish Pise
A new keyword -- calculated
Using Subqueries to Solve Queries
Subqueries.
Using Subqueries to Solve Queries
UNION Operator keywords Displays all rows from both the tables
The Selection Structure
2 Types of Subqueries.
MongoDB Read Operations
Control Structures.
Lab 2: Retrieving Data from the Database
Presentation transcript:

Subsetting Rows with the WHERE clause

Subsetting with the WHERE Clause Comparison Operators Mnemonic Symbol Definition LT † < Less than GT † > Greater than EQ † = Equal to LE † <= Less than or equal to GE † >= Greater than or equal to NE † < > ¬= † ^= † Not equal to Not equal to (EBCDIC) Not equal to (ASCII) † Non-ANSI standard

Create a list of personnel with salaries above $112,000 Create a list of personnel with salaries above $112,000. Include the employee identifier, job title, and salary. proc sql; select Employee_ID, Job_Title, Salary from orion.Staff where Salary > 112000 ; quit;

Use only one WHERE clause in a SELECT statement Use only one WHERE clause in a SELECT statement. To specify multiple subsetting criteria, combine expressions with logical operators. Mnemonic Symbol Definition OR | † or, either AND & † and, both NOT ¬ † not, negation (EBCDIC) ^ † not, negation (ASCII) † Non-ANSI standard

AND proc sql; select Employee_ID, Job_Title, Salary from orion.Staff where Salary > 112000 and gender="F" ; quit;

OR proc sql; select male,chol,sbp,dbp from s5238.chd5238 where sbp>250 or chol >450 ; quit;

NOT proc sql; select Employee_ID, Job_Title, Salary from orion.Staff where not (Salary <= 112000) ; quit;