A more complex example.

Slides:



Advertisements
Similar presentations
Oracle 10g & 11g for Dev Virtual Columns DML error logging
Advertisements

CS&E 1111 Exfunctions Using Functions in Excel Objectives: Using Excel functions l SUM, MIN, MAX, AVERAGE, COUNT, COUNTA l ROUND l COUNTIF, SUMIF, AVERAGEIF.
Restricting and sorting data 16 May May May Created By Pantharee Sawasdimongkol.
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.
Copyright  Oracle Corporation, All rights reserved. 6 Writing Correlated Subqueries.
11 Chapter 3: Displaying Query Results 3.1 Presenting Data 3.2 Summarizing Data.
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.
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.
Single-Row Functions. SQL Functions Functions are a very powerful feature of SQL and can be used to do the following: Perform calculations on data Modify.
11 Chapter 2: Basic Queries 2.1: Overview of the SQL Procedure 2.2: Specifying Columns 2.3: Specifying Rows.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 9 More About Strings.
Single-Row Functions. Two Types of SQL Functions There are two distinct types of functions: Single-row functions Multiple-row functions Single-Row Functions.
SINGLE-ROW FUNCTIONS Lecture 9. SQL Functions Functions are very powerful feature of SQL and can be used to do the following:  Perform a calculation.
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.
 Agenda 2/20/13 o Review quiz, answer questions o Review database design exercises from 2/13 o Create relationships through “Lookup tables” o Discuss.
SQL Chapter Two. Overview Basic Structure Verifying Statements Specifying Columns Specifying Rows.
IFS Intro to Data Management Chapter 5 Getting More Than Simple Columns.
Copyright © 2004, Oracle. All rights reserved. Lecture 4: 1-Retrieving Data Using the SQL SELECT Statement 2-Restricting and Sorting Data Lecture 4: 1-Retrieving.
Queries SELECT [DISTINCT] FROM ( { }| ),... [WHERE ] [GROUP BY [HAVING ]] [ORDER BY [ ],...]
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
I-1 Copyright س Oracle Corporation, All rights reserved. Data Retrieval.
Copyright س Oracle Corporation, All rights reserved. I Introduction.
2 Copyright © 2009, Oracle. All rights reserved. Restricting and Sorting Data.
Writing Basic SQL SELECT Statements Lecture
Limiting Selected Rows. 2-2 Objectives Sort row output using the ORDER BY clause. Sort row output using the ORDER BY clause. Enter search criteria using.
Single Row Functions Part I Week 2. Objectives –Describe types of single row functions in SQL –Describe and use character, number and date SQL functions.
Restricting and Sorting Data
Retrieving Data Using the SQL SELECT Statement
Microsoft Office Access 2010 Lab 3
Relational Database Design
Chapter 6: Set Operators
Writing Basic SQL SELECT Statements
Displaying Query Results
Aggregating Data Using Group Functions
Instructor: Craig Duckett Lecture 09: Tuesday, April 25th, 2017
Expressions and Control Flow in JavaScript
Basic Queries Specifying Columns
PROC SQL, Overview.
Using Subqueries to Solve Queries
Aggregating Data Using Group Functions
Correlated Subqueries
Restricting and Sorting Data
Displaying Queries 2 Display a query’s results in a specified order.
Subsetting Rows with the WHERE clause
Chapter 4 Summary Query.
Aggregating Data Using Group Functions
Grouping Summary Results
Using Subqueries to Solve Queries
Single-Row Functions Lecture 9.
Writing Basic SQL SELECT Statements
5 The EXCEPT Operator Unique rows from the first result set that are not found in the second result set are selected.
Basic String Operations
Using CASE Value expression
Reporting Aggregated Data Using the Group Functions
3 Specifying Rows.
Microsoft Visual Basic 2005: Reloaded Second Edition
Topics Basic String Operations String Slicing
A new keyword -- calculated
Restricting and Sorting Data
Subqueries.
ICT Database Lesson 2 Designing a Database.
Reporting Aggregated Data Using the Group Functions
UNION Operator keywords Displays all rows from both the tables
Lecture 5 SQL FUNCTIONS.
Reporting Aggregated Data Using the Group Functions
Topics Basic String Operations String Slicing
Database Programming Using Oracle 11g
02 | Querying Tables with SELECT
Topics Basic String Operations String Slicing
Presentation transcript:

A more complex example

M/E Ratio= # Managers / # non-Manager Employees Create a report that lists, for each department, the total number of managers, total number of employees, and the Employee-to-Manager (E/M) ratio. M/E Ratio= # Managers / # non-Manager Employees A rough sketch of the desired report. Department Managers Employees E/M Ratio Accounts 1 5 Administration 2 20 10 Department # Mgrs # Emps Emps/Mgrs

Counting Rows Meeting a Specified Criteria This request is complicated by the need, in the same query, to count rows that do have Manager in the title, as well as rows that do not. You cannot use a WHERE clause to exclude either group. Use the FIND function in a Boolean expression to simplify the query.

The FIND Function The FIND function returns the starting position of the first occurrence of a substring within a string (character value). General form of the FIND function: string constant, variable, or expression to be searched substring constant, variable, or expression sought within the string modifiers i=ignore case, t=trim trailing blanks startpos an integer specifying the start position and direction of the search FIND(string, substring<,modifier(s)><,startpos>)

Example data one; job_title="Administration Manager"; x=find(Job_Title,"manager","i"); run; proc print data=one;run;

The FIND Function -- Find the starting position of the substring Manager in the character variable Job_Title. The value returned by the FIND function is 16. find(Job_Title,"manager","i") Job_Title 1 2 3 4 5 6 7 8 9 A d m i n s t r a o M g e

If the substring is not found in string, FIND returns a value of 0. data one; job_title="Administration Manager"; x=find(Job_Title,"manager"); run; proc print data=one;run;

Using Boolean Expressions Boolean expressions evaluate to TRUE (1) or FALSE (0). They are used in this SELECT list to distinguish rows that have Manager in the Job_Title column. proc sql ; select Department,Job_Title, (find(Job_Title,"manager","i") >0) "Manager" from orion.Employee_Organization ; quit; s103d12 The Boolean expression will produce the value 1 when Job_Title contains the word Manager and 0 when it does not.

Using Boolean Expressions -- For each department, calculate the percentage of people with the word Manager in the job title. proc sql; title "Manager to Employee Ratios"; select Department, sum((find(Job_Title,"manager","i") >0)) as Managers, sum((find(Job_Title,"manager","i") =0)) as Employees, calculated Employees/calculated Managers "E/M Ratio" format=8.3 from orion.Employee_Organization group by Department ; quit; s103d13