This presentation describes about the following topics
Logical Operators
LISTS (IN AND NOT IN)
RANGES (BETWEEN AND NOT BETWEEN)
ORDER BY
Aggregate functions
GROUP BY and HAVING
UNION
This document summarizes various SQL operators and built-in functions. It describes arithmetic, relational, logical, and string operators. It also discusses different types of built-in functions including character, numeric, date, aggregate/group, conversion, and general functions. Examples are provided to demonstrate how each operator and function works.
Consists of the explanations of the basics of SQL and commands of SQL.Helpful for II PU NCERT students and also degree studeents to understand some basic things.
Joins in SQL are used to combine data from two or more tables based on common columns between them. There are several types of joins, including inner joins, outer joins, and cross joins. Inner joins return rows that match between tables, outer joins return all rows including non-matching rows, and cross joins return the cartesian product between tables.
The document discusses different types of joins in SQL for combining data from multiple tables, including inner joins, outer joins, natural joins, joins using the USING clause, and self-joins using the ON clause. It provides examples of SQL queries for left, right, full, and cross joins. Cross joins produce the cartesian product of all rows in two tables, while inner and outer joins match rows based on join conditions.
This document discusses various SQL functions in DBMS including single row functions, group functions, character functions, number functions, date functions, and conversion functions. It provides examples of commonly used functions like ROUND, TRUNC, SQRT, MOD, DATE functions, and TO_CHAR/TO_DATE conversion functions. It also covers general functions like NVL, NVL2, NULLIF, COALESCE, CASE, and DECODE that can work on different data types and avoid null values. Set operators are briefly mentioned to combine multiple queries.
Single-row functions allow users to manipulate data within SQL queries. Common types include character, number, date, and conversion functions. Character functions modify strings, number functions perform calculations, date functions work with dates, and conversion functions change data types. Functions are useful for formatting output, performing calculations on individual rows, and conditional processing.
Operators and expressions in c languagetanmaymodi4
what is operator in c language
uses of operator in c language
syatax of operator in c language
program of operator in c language
what is expressions in c language
use of expressions in c language
syantax of expressions in c language
Dynamic memory allocation allows programs to request memory from the operating system at runtime. This memory is allocated on the heap. Functions like malloc(), calloc(), and realloc() are used to allocate and reallocate dynamic memory, while free() releases it. Malloc allocates a single block of uninitialized memory. Calloc allocates multiple blocks of initialized (zeroed) memory. Realloc changes the size of previously allocated memory. Proper use of these functions avoids memory leaks.
This document summarizes various SQL operators and built-in functions. It describes arithmetic, relational, logical, and string operators. It also discusses different types of built-in functions including character, numeric, date, aggregate/group, conversion, and general functions. Examples are provided to demonstrate how each operator and function works.
Consists of the explanations of the basics of SQL and commands of SQL.Helpful for II PU NCERT students and also degree studeents to understand some basic things.
Joins in SQL are used to combine data from two or more tables based on common columns between them. There are several types of joins, including inner joins, outer joins, and cross joins. Inner joins return rows that match between tables, outer joins return all rows including non-matching rows, and cross joins return the cartesian product between tables.
The document discusses different types of joins in SQL for combining data from multiple tables, including inner joins, outer joins, natural joins, joins using the USING clause, and self-joins using the ON clause. It provides examples of SQL queries for left, right, full, and cross joins. Cross joins produce the cartesian product of all rows in two tables, while inner and outer joins match rows based on join conditions.
This document discusses various SQL functions in DBMS including single row functions, group functions, character functions, number functions, date functions, and conversion functions. It provides examples of commonly used functions like ROUND, TRUNC, SQRT, MOD, DATE functions, and TO_CHAR/TO_DATE conversion functions. It also covers general functions like NVL, NVL2, NULLIF, COALESCE, CASE, and DECODE that can work on different data types and avoid null values. Set operators are briefly mentioned to combine multiple queries.
Single-row functions allow users to manipulate data within SQL queries. Common types include character, number, date, and conversion functions. Character functions modify strings, number functions perform calculations, date functions work with dates, and conversion functions change data types. Functions are useful for formatting output, performing calculations on individual rows, and conditional processing.
Operators and expressions in c languagetanmaymodi4
what is operator in c language
uses of operator in c language
syatax of operator in c language
program of operator in c language
what is expressions in c language
use of expressions in c language
syantax of expressions in c language
Dynamic memory allocation allows programs to request memory from the operating system at runtime. This memory is allocated on the heap. Functions like malloc(), calloc(), and realloc() are used to allocate and reallocate dynamic memory, while free() releases it. Malloc allocates a single block of uninitialized memory. Calloc allocates multiple blocks of initialized (zeroed) memory. Realloc changes the size of previously allocated memory. Proper use of these functions avoids memory leaks.
SQL is a standard language for querying and manipulating data in relational databases. It contains five categories of statements: data definition language (DDL) for defining data structure, data manipulation language (DML) for managing data, data control language (DCL) for privileges, transaction control statements for transactions, and session control statements for sessions. Common DDL commands include CREATE, ALTER, and DROP for databases and tables. Common DML commands include SELECT, INSERT, UPDATE, and DELETE for querying and modifying data. Joins are used to combine data from two or more tables.
Strings in Python are arrays of bytes representing Unicode characters. Individual characters in a string can be accessed using indexes and slices. Strings are immutable, so their elements cannot be changed once created.
Various methods are available for string manipulation in Python. These include methods for accessing characters by index or slice, checking substrings, converting case, padding/stripping strings, and more. Character methods like ord() and chr() allow getting ASCII values and characters.
This chapter discusses advanced SQL features including relational set operators like UNION and INTERSECT, different types of joins, subqueries, functions, views, triggers, stored procedures, cursors, and embedded SQL. It covers topics like using subqueries in the SELECT, WHERE, HAVING and FROM clauses, correlated subqueries, date/string/numeric functions, updatable views, procedural language features in PL/SQL including triggers and stored procedures, and static versus dynamic embedded SQL.
SQL is a standard language for accessing and manipulating databases. It allows users to retrieve, insert, update, and delete data as well as create new databases and tables. Common SQL statements include SELECT, UPDATE, DELETE, and INSERT. SQL uses clauses, operators, and wildcards to filter records based on conditions. Some key points are that SQL is an ANSI standard but different versions exist, it allows querying and modifying data in databases, and is essential for interacting with relational database systems.
This document discusses C++ streams and stream classes. It explains that streams represent the flow of data in C++ programs and are controlled using classes. The key classes are istream for input, ostream for output, and fstream for file input/output. It provides examples of reading from and writing to files using fstream, and describes various stream manipulators like endl. The document also discusses the filebuf and streambuf base classes that perform low-level input/output operations.
The document discusses how computers represent and encode data and characters. It describes:
- Bits and bytes as the basic units of digital information
- Character codes like ASCII and EBCDIC that represent characters as numeric codes to allow computers to process text
- How ASCII in particular assigns a unique 8-bit binary number to each letter, number, and symbol
Two dimensional arrays in C can be declared and initialized similarly to one dimensional arrays, with the first subscript specifying the row and second subscript specifying the column. Elements are stored in contiguous memory locations in row-major order. The document then presents a sample problem of reading a 2D array of integers from a file, finding the largest element, and printing it out. It also discusses using typedef to define custom data types like matrices and strings.
The document discusses referential integrity in relational databases. It explains that referential integrity requires primary keys and foreign keys to be consistent, so that foreign keys always match existing primary keys in linked tables. This prevents issues like orphaned records or adding records that reference nonexistent keys. Referential integrity guarantees consistency between linked tables and helps maintain data integrity.
The document contains 16 sections that describe database management system experiments to be performed. Each section includes instructions to create and manipulate tables, perform queries, and implement concepts like triggers, functions, stored procedures, cursors, and embedded SQL. Students will connect to databases and design systems for payroll, banking, and a library using Visual Basic. Their work will be evaluated based on aim and description, queries, results, output, and records.
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
SQL - Structured query language introductionSmriti Jain
SQL is a language used to define, manipulate, and control relational databases. It has four main components: DDL for defining schemas; DML for manipulating data within schemas; DCL for controlling access privileges; and DQL for querying data. Some key SQL concepts covered include data definition using CREATE, ALTER, DROP statements; data manipulation using SELECT, INSERT, UPDATE, DELETE; and joining data across tables using conditions. Advanced topics include views, aggregation, subqueries, and modifying databases.
This document discusses data structures and linked lists. It provides definitions and examples of different types of linked lists, including:
- Single linked lists, which contain nodes with a data field and a link to the next node.
- Circular linked lists, where the last node links back to the first node, forming a loop.
- Doubly linked lists, where each node contains links to both the previous and next nodes.
- Operations on linked lists such as insertion, deletion, traversal, and searching are also described.
Relational Algebra is a procedural query language consisting of a set of operations that take one or two relations as input and produce a new relation as output. The fundamental operations in Relational Algebra are selection, projection, union, set difference, cartesian product, and join. Selection chooses tuples that meet a selection condition, projection chooses attributes from a relation, union includes all tuples from two relations, set difference includes tuples from one relation not in another, cartesian product creates all combinations of tuples from two relations, and join compounds similar tuples from two relations.
This document discusses two-dimensional arrays. It begins by defining two-dimensional arrays as arrangements of elements in rows and columns with two indices - one for the row and one for the column. It then covers declaring, initializing, accessing, inputting, outputting, and performing operations on two-dimensional arrays and matrices. Specific operations discussed include traversing arrays, summing row/column elements, and performing operations on matrices like finding diagonal sums and adding matrices.
This document discusses aggregate functions in SQL. It defines aggregate functions as functions that summarize expression results over multiple rows into a single value. Commonly used aggregate functions include SUM, COUNT, AVG, MIN, and MAX. Examples are provided calculating sums, averages, minimums, and maximums of salaries in an employee table to illustrate the use of these functions. It also discusses issues like ignoring null values and the need to use the GROUP BY clause with aggregate functions.
SQL is a standard language for accessing and manipulating databases. The document provides an introduction to SQL basics including SQL statements to select, insert, update and delete data from database tables. It explains key SQL components like the WHERE clause for filtering records and the ORDER BY clause for sorting query results. Examples are given for each SQL statement and concept discussed.
The document discusses implementation of stacks. It describes stacks as linear data structures that follow LIFO principles. Key stack operations like push and pop are outlined. Stacks are often implemented using arrays or linked lists. Examples of stack applications include recursion handling, expression evaluation, parenthesis checking, and backtracking problems. Conversion from infix to postfix notation using a stack is also demonstrated.
This document discusses different searching methods like sequential, binary, and hashing. It defines searching as finding an element within a list. Sequential search searches lists sequentially until the element is found or the end is reached, with efficiency of O(n) in worst case. Binary search works on sorted arrays by eliminating half of remaining elements at each step, with efficiency of O(log n). Hashing maps keys to table positions using a hash function, allowing searches, inserts and deletes in O(1) time on average. Good hash functions uniformly distribute keys and generate different hashes for similar keys.
Join queries combine data from two or more tables in a database. An inner join returns rows where there is a match between columns in both tables. A left join returns all rows from the left table, along with matched rows from the right table, returning null if there is no match. A right join is similar but returns all rows from the right table. A full join returns all rows and fills in nulls for missing matches between the tables.
Complex Queries using MYSQL00123211.pptxmetriohanzel
The document describes creating sample tables and inserting demo data for SQL exercises. It includes commands to create DEPARTMENT and EMPLOYEE tables, alter their structures, and insert sample records. It then provides 5 complex SQL queries as examples for a database engineer, such as finding departments by location, employees by department, average salary by department, and the top 10 highest-paid employees.
Restricting and Sorting Data - Oracle Data BaseSalman Memon
This document discusses how to restrict and sort data retrieved by SQL queries. It describes how to limit rows using the WHERE clause with various comparison operators like equal to, greater than, between, in, like, and is null. Logical operators like AND, OR and NOT can be used with WHERE. Rows can be sorted using the ORDER BY clause, specifying columns and expressions to sort on in ascending or descending order. Multiple columns can be used in the ORDER BY to further refine the sorting.
SQL is a standard language for querying and manipulating data in relational databases. It contains five categories of statements: data definition language (DDL) for defining data structure, data manipulation language (DML) for managing data, data control language (DCL) for privileges, transaction control statements for transactions, and session control statements for sessions. Common DDL commands include CREATE, ALTER, and DROP for databases and tables. Common DML commands include SELECT, INSERT, UPDATE, and DELETE for querying and modifying data. Joins are used to combine data from two or more tables.
Strings in Python are arrays of bytes representing Unicode characters. Individual characters in a string can be accessed using indexes and slices. Strings are immutable, so their elements cannot be changed once created.
Various methods are available for string manipulation in Python. These include methods for accessing characters by index or slice, checking substrings, converting case, padding/stripping strings, and more. Character methods like ord() and chr() allow getting ASCII values and characters.
This chapter discusses advanced SQL features including relational set operators like UNION and INTERSECT, different types of joins, subqueries, functions, views, triggers, stored procedures, cursors, and embedded SQL. It covers topics like using subqueries in the SELECT, WHERE, HAVING and FROM clauses, correlated subqueries, date/string/numeric functions, updatable views, procedural language features in PL/SQL including triggers and stored procedures, and static versus dynamic embedded SQL.
SQL is a standard language for accessing and manipulating databases. It allows users to retrieve, insert, update, and delete data as well as create new databases and tables. Common SQL statements include SELECT, UPDATE, DELETE, and INSERT. SQL uses clauses, operators, and wildcards to filter records based on conditions. Some key points are that SQL is an ANSI standard but different versions exist, it allows querying and modifying data in databases, and is essential for interacting with relational database systems.
This document discusses C++ streams and stream classes. It explains that streams represent the flow of data in C++ programs and are controlled using classes. The key classes are istream for input, ostream for output, and fstream for file input/output. It provides examples of reading from and writing to files using fstream, and describes various stream manipulators like endl. The document also discusses the filebuf and streambuf base classes that perform low-level input/output operations.
The document discusses how computers represent and encode data and characters. It describes:
- Bits and bytes as the basic units of digital information
- Character codes like ASCII and EBCDIC that represent characters as numeric codes to allow computers to process text
- How ASCII in particular assigns a unique 8-bit binary number to each letter, number, and symbol
Two dimensional arrays in C can be declared and initialized similarly to one dimensional arrays, with the first subscript specifying the row and second subscript specifying the column. Elements are stored in contiguous memory locations in row-major order. The document then presents a sample problem of reading a 2D array of integers from a file, finding the largest element, and printing it out. It also discusses using typedef to define custom data types like matrices and strings.
The document discusses referential integrity in relational databases. It explains that referential integrity requires primary keys and foreign keys to be consistent, so that foreign keys always match existing primary keys in linked tables. This prevents issues like orphaned records or adding records that reference nonexistent keys. Referential integrity guarantees consistency between linked tables and helps maintain data integrity.
The document contains 16 sections that describe database management system experiments to be performed. Each section includes instructions to create and manipulate tables, perform queries, and implement concepts like triggers, functions, stored procedures, cursors, and embedded SQL. Students will connect to databases and design systems for payroll, banking, and a library using Visual Basic. Their work will be evaluated based on aim and description, queries, results, output, and records.
PL/SQL is a combination of SQL along with the procedural features of programming languages.
It provides specific syntax for this purpose and supports exactly the same datatypes as SQL.
SQL - Structured query language introductionSmriti Jain
SQL is a language used to define, manipulate, and control relational databases. It has four main components: DDL for defining schemas; DML for manipulating data within schemas; DCL for controlling access privileges; and DQL for querying data. Some key SQL concepts covered include data definition using CREATE, ALTER, DROP statements; data manipulation using SELECT, INSERT, UPDATE, DELETE; and joining data across tables using conditions. Advanced topics include views, aggregation, subqueries, and modifying databases.
This document discusses data structures and linked lists. It provides definitions and examples of different types of linked lists, including:
- Single linked lists, which contain nodes with a data field and a link to the next node.
- Circular linked lists, where the last node links back to the first node, forming a loop.
- Doubly linked lists, where each node contains links to both the previous and next nodes.
- Operations on linked lists such as insertion, deletion, traversal, and searching are also described.
Relational Algebra is a procedural query language consisting of a set of operations that take one or two relations as input and produce a new relation as output. The fundamental operations in Relational Algebra are selection, projection, union, set difference, cartesian product, and join. Selection chooses tuples that meet a selection condition, projection chooses attributes from a relation, union includes all tuples from two relations, set difference includes tuples from one relation not in another, cartesian product creates all combinations of tuples from two relations, and join compounds similar tuples from two relations.
This document discusses two-dimensional arrays. It begins by defining two-dimensional arrays as arrangements of elements in rows and columns with two indices - one for the row and one for the column. It then covers declaring, initializing, accessing, inputting, outputting, and performing operations on two-dimensional arrays and matrices. Specific operations discussed include traversing arrays, summing row/column elements, and performing operations on matrices like finding diagonal sums and adding matrices.
This document discusses aggregate functions in SQL. It defines aggregate functions as functions that summarize expression results over multiple rows into a single value. Commonly used aggregate functions include SUM, COUNT, AVG, MIN, and MAX. Examples are provided calculating sums, averages, minimums, and maximums of salaries in an employee table to illustrate the use of these functions. It also discusses issues like ignoring null values and the need to use the GROUP BY clause with aggregate functions.
SQL is a standard language for accessing and manipulating databases. The document provides an introduction to SQL basics including SQL statements to select, insert, update and delete data from database tables. It explains key SQL components like the WHERE clause for filtering records and the ORDER BY clause for sorting query results. Examples are given for each SQL statement and concept discussed.
The document discusses implementation of stacks. It describes stacks as linear data structures that follow LIFO principles. Key stack operations like push and pop are outlined. Stacks are often implemented using arrays or linked lists. Examples of stack applications include recursion handling, expression evaluation, parenthesis checking, and backtracking problems. Conversion from infix to postfix notation using a stack is also demonstrated.
This document discusses different searching methods like sequential, binary, and hashing. It defines searching as finding an element within a list. Sequential search searches lists sequentially until the element is found or the end is reached, with efficiency of O(n) in worst case. Binary search works on sorted arrays by eliminating half of remaining elements at each step, with efficiency of O(log n). Hashing maps keys to table positions using a hash function, allowing searches, inserts and deletes in O(1) time on average. Good hash functions uniformly distribute keys and generate different hashes for similar keys.
Join queries combine data from two or more tables in a database. An inner join returns rows where there is a match between columns in both tables. A left join returns all rows from the left table, along with matched rows from the right table, returning null if there is no match. A right join is similar but returns all rows from the right table. A full join returns all rows and fills in nulls for missing matches between the tables.
Complex Queries using MYSQL00123211.pptxmetriohanzel
The document describes creating sample tables and inserting demo data for SQL exercises. It includes commands to create DEPARTMENT and EMPLOYEE tables, alter their structures, and insert sample records. It then provides 5 complex SQL queries as examples for a database engineer, such as finding departments by location, employees by department, average salary by department, and the top 10 highest-paid employees.
Restricting and Sorting Data - Oracle Data BaseSalman Memon
This document discusses how to restrict and sort data retrieved by SQL queries. It describes how to limit rows using the WHERE clause with various comparison operators like equal to, greater than, between, in, like, and is null. Logical operators like AND, OR and NOT can be used with WHERE. Rows can be sorted using the ORDER BY clause, specifying columns and expressions to sort on in ascending or descending order. Multiple columns can be used in the ORDER BY to further refine the sorting.
Les02 Restricting and Sorting Data using SQL.pptDrZeeshanBhatti
While retrieving data from the database, you may need to restrict the rows of data that are displayed or specify the order in which the rows are displayed. This lesson explains the SQL statements that you use to perform these actions.
How did i steal your database CSCamp2011Mostafa Siraj
This document discusses how SQL injection attacks can be used to steal database information. It begins by providing background on databases and SQL queries. It then explains how SQL injection works by altering existing SQL commands. Several examples are given of SQL injection attacks, like exploiting unvalidated login forms. The document outlines a step-by-step strategy an attacker could use to extract metadata and data from a database using SQL injection, including getting the database type and table/column names. It concludes by demonstrating how an attacker could use the extracted information to add an administrative account.
The document discusses various SQL functions like NVL, NVL2 and subqueries. It provides examples of using these functions and subqueries to return employee data based on conditions. It also discusses creating a user defined function to check if an employee's salary is greater than the average salary in their department. The function is modified to accept an employee ID as a parameter rather than being hardcoded.
The document discusses the topics covered in a database technologies course, including relational algebra operations. It provides examples and explanations of relational algebra concepts like selection, projection, join, union, difference, and cartesian product. It also discusses limitations of relational algebra in expressing complex queries involving transitive closure. The document contains practice questions related to relational algebra operations at the end.
The document provides an introduction to the SQL language, including its main components of DML (Data Manipulation Language) and DDL (Data Definition Language). It discusses SQL concepts such as creating tables with data types, defining primary and foreign keys, and using basic queries with SELECT, FROM, WHERE and ORDER BY clauses.
This document discusses an introduction to structured query language (SQL) presented by Dr. C.V. Suresh Babu. The presentation covers SQL queries including SELECT, INSERT, UPDATE, and DELETE queries. Examples are provided for how to query, create, add, edit, and delete records from database tables. The document concludes with a quiz on SQL concepts.
SQL is a standard language for accessing and manipulating databases. It allows users to query, insert, update, and delete data. The document discusses SQL statements like SELECT, INSERT, UPDATE, DELETE and functions like JOIN, aggregate functions, and scalar functions. It provides examples of creating tables and manipulating data using DDL, DML, and DCL statements. Joins allow combining data from multiple tables based on common fields.
Melbourne Groundbreakers Tour - Upgrading without riskConnor McDonald
The 12c optimizer has a vast array of improvements, but of course, functionality changes means that your SQL plans might also change when you upgrade. This slidedeck covers what has changed, and how to ensure better more stable performance when you upgrade.
The 12c optimizer has a vast array of improvements, but of course, functionality changes means that your SQL plans might also change when you upgrade. This slidedeck covers what has changed, and how to ensure better more stable performance when you upgrade.
This document provides an introduction to Structured Query Language (SQL) and T-SQL. It discusses the basic SELECT statement and how to select data from single and multiple tables using various join types. The key topics covered include the SELECT statement syntax, arithmetic and logical operators, filtering rows with WHERE, sorting with ORDER BY, and performing inner, outer, left, right and full joins. Examples are provided throughout to illustrate each SQL concept.
So you are young and single – you are standing in a crowded room and you are looking to connect with all the people that match the criteria of your perfect partner. How do you identify and grab the details of those individuals as quickly as possible, without spending too much time talking to people you will never get on with. This presentation will use a situation we have all been familiar with to explain how the optimizer works, the steps in the optimisation process and some of the rules that help it to score a match as efficiently as possible.
SQL queries can contain up to six clauses but only SELECT and FROM are mandatory. The clauses are evaluated in a specific order. Nested queries allow queries to be specified within other queries and can be correlated or uncorrelated. The ORDER BY clause sorts result tuples based on attribute values. The three modification commands are INSERT to add tuples, DELETE to remove tuples, and UPDATE to modify tuples.
SQL queries can contain up to six clauses but only SELECT and FROM are mandatory. The clauses are evaluated in a specific order. Nested queries allow queries to be specified within other queries and can be correlated or uncorrelated. The ORDER BY clause sorts result tuples based on attribute values. The three modification commands are INSERT to add tuples, DELETE to remove tuples, and UPDATE to modify tuples.
The document discusses SQL queries and updates. It describes the six clauses of an SQL query (SELECT, FROM, WHERE, GROUP BY, HAVING, ORDER BY), with SELECT and FROM being mandatory. It provides examples of different types of queries, including nested and correlated subqueries. It also covers the three SQL commands for modifying the database - INSERT for adding new tuples, DELETE for removing tuples, and UPDATE for modifying tuples. INSERT allows adding a single tuple or multiple tuples from a query result.
This document provides an overview of SQL functions and grouping data in SQL. It discusses aggregate functions that return a single calculated value from a column, and scalar functions that return a single value for each row. Examples of aggregate functions like SUM, AVING, and MIN are provided. Scalar functions like UCASE and LCASE are also demonstrated. The document explains how the GROUP BY clause allows grouping result sets and running aggregate queries on the groups. It then covers the HAVING clause, which filters grouped data. Finally, it discusses different types of joins in SQL like inner joins, left outer joins, and right outer joins along with examples.
This document contains SQL queries and questions related to selecting, filtering, ordering, grouping, joining, and manipulating data in employee and incentives tables. It includes questions on selecting specific columns, filtering by conditions, ordering results, performing string operations and date functions, grouping and aggregating data, different join types, and DML statements for modifying table structures and data.
This document discusses restricting and sorting data in Oracle. It covers limiting rows using the WHERE clause, sorting rows using the ORDER BY clause, and using ampersand substitution in iSQL*Plus to restrict and sort output at runtime. Comparison operators, logical operators, NULL conditions, character strings, dates and BETWEEN/IN/LIKE conditions for the WHERE clause are explained. Best practices for ORDER BY are also provided.
This document provides tips for optimizing SQL queries to improve performance. Some key recommendations include:
1) Select only necessary columns instead of using SELECT * to reduce overhead
2) Use EXISTS, IN, and joins appropriately depending on where filter criteria is specified
3) Minimize subqueries and try to rewrite queries using joins when possible
4) Be cautious of conditions in the WHERE clause to ensure optimal execution order
This presentation discusses the following topics:
Basic features of R
Exploring R GUI
Data Frames & Lists
Handling Data in R Workspace
Reading Data Sets & Exporting Data from R
Manipulating & Processing Data in R
Association rule mining is used to find relationships between items in transaction data. It identifies rules that can predict the occurrence of an item based on other items purchased together frequently. Some key metrics used to evaluate rules include support, which measures how frequently an itemset occurs; confidence, which measures how often items in the predicted set occur given items in the predictor set; and lift, which compares the confidence to expected confidence if items were independent. An example association rule evaluated is {Milk, Diaper} -> {Beer} with support of 0.4, confidence of 0.67, and lift of 1.11.
This document discusses clustering, which is the task of grouping data points into clusters so that points within the same cluster are more similar to each other than points in other clusters. It describes different types of clustering methods, including density-based, hierarchical, partitioning, and grid-based methods. It provides examples of specific clustering algorithms like K-means, DBSCAN, and discusses applications of clustering in fields like marketing, biology, libraries, insurance, city planning, and earthquake studies.
Classification is a data analysis technique used to predict class membership for new observations based on a training set of previously labeled examples. It involves building a classification model during a training phase using an algorithm, then testing the model on new data to estimate accuracy. Some common classification algorithms include decision trees, Bayesian networks, neural networks, and support vector machines. Classification has applications in domains like medicine, retail, and entertainment.
The document discusses the assumptions and properties of ordinary least squares (OLS) estimators in linear regression analysis. It notes that OLS estimators are best linear unbiased estimators (BLUE) if the assumptions of the linear regression model are met. Specifically, it assumes errors have zero mean and constant variance, are uncorrelated, and are normally distributed. Violation of the assumption of constant variance is known as heteroscedasticity. The document outlines how heteroscedasticity impacts the properties of OLS estimators and their use in applications like econometrics.
This document provides an introduction to regression analysis. It discusses that regression analysis investigates the relationship between dependent and independent variables to model and analyze data. The document outlines different types of regressions including linear, polynomial, stepwise, ridge, lasso, and elastic net regressions. It explains that regression analysis is used for predictive modeling, forecasting, and determining the impact of variables. The benefits of regression analysis are that it indicates significant relationships and the strength of impact between variables.
MYCIN was an early expert system developed at Stanford University in 1972 to assist physicians in diagnosing and selecting treatment for bacterial and blood infections. It used over 600 production rules encoding the clinical decision criteria of infectious disease experts to diagnose patients based on reported symptoms and test results. While it could not replace human diagnosis due to computing limitations at the time, MYCIN demonstrated that expert knowledge could be represented computationally and established a foundation for more advanced machine learning and knowledge base systems.
The document discusses expert systems, which are computer applications that solve complex problems at a human expert level. It describes the characteristics and capabilities of expert systems, why they are useful, and their key components - knowledge base, inference engine, and user interface. The document also outlines common applications of expert systems and the general development process.
The Dempster-Shafer Theory was developed by Arthur Dempster in 1967 and Glenn Shafer in 1976 as an alternative to Bayesian probability. It allows one to combine evidence from different sources and obtain a degree of belief (or probability) for some event. The theory uses belief functions and plausibility functions to represent degrees of belief for various hypotheses given certain evidence. It was developed to describe ignorance and consider all possible outcomes, unlike Bayesian probability which only considers single evidence. An example is given of using the theory to determine the murderer in a room with 4 people where the lights went out.
A Bayesian network is a probabilistic graphical model that represents conditional dependencies among random variables using a directed acyclic graph. It consists of nodes representing variables and directed edges representing causal relationships. Each node contains a conditional probability table that quantifies the effect of its parent nodes on that variable. Bayesian networks can be used to calculate the probability of events occurring based on the network structure and conditional probability tables, such as computing the probability of an alarm sounding given that no burglary or earthquake occurred but two neighbors called.
This document discusses knowledge-based agents in artificial intelligence. It defines knowledge-based agents as agents that maintain an internal state of knowledge, reason over that knowledge, update their knowledge based on observations, and take actions. Knowledge-based agents have two main components: a knowledge base that stores facts about the world, and an inference system that applies logical rules to deduce new information from the knowledge base. The document also describes the architecture of knowledge-based agents and different approaches to designing them.
A rule-based system uses predefined rules to make logical deductions and choices to perform automated actions. It consists of a database of rules representing knowledge, a database of facts as inputs, and an inference engine that controls the process of deriving conclusions by applying rules to facts. A rule-based system mimics human decision making by applying rules in an "if-then" format to incoming data to perform actions, but unlike AI it does not learn or adapt on its own.
This document discusses formal logic and its applications in AI and machine learning. It begins by explaining why logic is useful in complex domains or with little data. It then describes logic-based approaches to AI that use symbolic reasoning as an alternative to machine learning. The document proceeds to explain propositional logic and first-order logic, noting how first-order logic improves on propositional logic by allowing variables. It also mentions other logics and their applications in areas like automated discovery, inductive programming, and verification of computer systems and machine learning models.
The document discusses production systems, which are rule-based systems used in artificial intelligence to model intelligent behavior. A production system consists of a global database, set of production rules, and control system. The rules fire to modify the database based on conditions. Different control strategies are used to determine which rules fire. Production systems are modular and allow knowledge representation as condition-action rules. Examples of applications in problem solving are provided.
The document discusses game playing in artificial intelligence. It describes how general game playing (GGP) involves designing AI that can play multiple games by learning the rules, rather than being programmed for a specific game. The document outlines how the minimax algorithm is commonly used for game playing, involving move generation and static evaluation functions to search game trees and determine the best move by maximizing or minimizing values at each level.
A study on “Diagnosis Test of Diabetics and Hypertension by AI”, Presentation slides for International Conference on "Life Sciences: Acceptance of the New Normal", St. Aloysius' College, Jabalpur, Madhya Pradesh, India, 27-28 August, 2021
A study on “impact of artificial intelligence in covid19 diagnosis”Dr. C.V. Suresh Babu
A study on “Impact of Artificial Intelligence in COVID-19 Diagnosis”, Presentation slides for International Conference on "Life Sciences: Acceptance of the New Normal", St. Aloysius' College, Jabalpur, Madhya Pradesh, India, 27-28 August, 2021
A study on “impact of artificial intelligence in covid19 diagnosis”Dr. C.V. Suresh Babu
Although the lungs are one of the most vital organs in the body, they are vulnerable to infection and injury. COVID-19 has put the entire world in an unprecedented difficult situation, bringing life to a halt and claiming thousands of lives all across the world. Medical imaging, such as X-rays and computed tomography (CT), is essential in the global fight against COVID-19, and newly emerging artificial intelligence (AI) technologies are boosting the power of imaging tools and assisting medical specialists. AI can improve job efficiency by precisely identifying infections in X-ray and CT images and allowing further measurement. We focus on the integration of AI with X-ray and CT, both of which are routinely used in frontline hospitals, to reflect the most recent progress in medical imaging and radiology combating COVID-19.
The chapter Lifelines of National Economy in Class 10 Geography focuses on the various modes of transportation and communication that play a vital role in the economic development of a country. These lifelines are crucial for the movement of goods, services, and people, thereby connecting different regions and promoting economic activities.
This document provides an overview of wound healing, its functions, stages, mechanisms, factors affecting it, and complications.
A wound is a break in the integrity of the skin or tissues, which may be associated with disruption of the structure and function.
Healing is the body’s response to injury in an attempt to restore normal structure and functions.
Healing can occur in two ways: Regeneration and Repair
There are 4 phases of wound healing: hemostasis, inflammation, proliferation, and remodeling. This document also describes the mechanism of wound healing. Factors that affect healing include infection, uncontrolled diabetes, poor nutrition, age, anemia, the presence of foreign bodies, etc.
Complications of wound healing like infection, hyperpigmentation of scar, contractures, and keloid formation.
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxEduSkills OECD
Iván Bornacelly, Policy Analyst at the OECD Centre for Skills, OECD, presents at the webinar 'Tackling job market gaps with a skills-first approach' on 12 June 2024
How to Make a Field Mandatory in Odoo 17Celine George
In Odoo, making a field required can be done through both Python code and XML views. When you set the required attribute to True in Python code, it makes the field required across all views where it's used. Conversely, when you set the required attribute in XML views, it makes the field required only in the context of that particular view.
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.pptHenry Hollis
The History of NZ 1870-1900.
Making of a Nation.
From the NZ Wars to Liberals,
Richard Seddon, George Grey,
Social Laboratory, New Zealand,
Confiscations, Kotahitanga, Kingitanga, Parliament, Suffrage, Repudiation, Economic Change, Agriculture, Gold Mining, Timber, Flax, Sheep, Dairying,
This presentation was provided by Racquel Jemison, Ph.D., Christina MacLaughlin, Ph.D., and Paulomi Majumder. Ph.D., all of the American Chemical Society, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.
How to Setup Warehouse & Location in Odoo 17 InventoryCeline George
In this slide, we'll explore how to set up warehouses and locations in Odoo 17 Inventory. This will help us manage our stock effectively, track inventory levels, and streamline warehouse operations.
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumMJDuyan
(𝐓𝐋𝐄 𝟏𝟎𝟎) (𝐋𝐞𝐬𝐬𝐨𝐧 𝟏)-𝐏𝐫𝐞𝐥𝐢𝐦𝐬
𝐃𝐢𝐬𝐜𝐮𝐬𝐬 𝐭𝐡𝐞 𝐄𝐏𝐏 𝐂𝐮𝐫𝐫𝐢𝐜𝐮𝐥𝐮𝐦 𝐢𝐧 𝐭𝐡𝐞 𝐏𝐡𝐢𝐥𝐢𝐩𝐩𝐢𝐧𝐞𝐬:
- Understand the goals and objectives of the Edukasyong Pantahanan at Pangkabuhayan (EPP) curriculum, recognizing its importance in fostering practical life skills and values among students. Students will also be able to identify the key components and subjects covered, such as agriculture, home economics, industrial arts, and information and communication technology.
𝐄𝐱𝐩𝐥𝐚𝐢𝐧 𝐭𝐡𝐞 𝐍𝐚𝐭𝐮𝐫𝐞 𝐚𝐧𝐝 𝐒𝐜𝐨𝐩𝐞 𝐨𝐟 𝐚𝐧 𝐄𝐧𝐭𝐫𝐞𝐩𝐫𝐞𝐧𝐞𝐮𝐫:
-Define entrepreneurship, distinguishing it from general business activities by emphasizing its focus on innovation, risk-taking, and value creation. Students will describe the characteristics and traits of successful entrepreneurs, including their roles and responsibilities, and discuss the broader economic and social impacts of entrepreneurial activities on both local and global scales.
This presentation was provided by Rebecca Benner, Ph.D., of the American Society of Anesthesiologists, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.
spot a liar (Haiqa 146).pptx Technical writhing and presentation skills
SQL logical operators
1. Department of Information Technology 1Data base Technologies (ITB4201)
Structured Query Language
Logical Operators
Dr. C.V. Suresh Babu
Professor
Department of IT
Hindustan Institute of Science & Technology
2. Department of Information Technology 2Data base Technologies (ITB4201)
Action Plan
• Logical Operators
• LISTS (IN AND NOT IN)
• RANGES (BETWEEN AND NOT BETWEEN)
• ORDER BY
• Aggregate functions
• GROUP BY and HAVING
• UNION
3. Department of Information Technology 3Data base Technologies (ITB4201)
LOGICAL OPERATORS
(AND, OR, AND NOT)
• AND : Joins two or more conditions, and returns results only
when all of the conditions are true.
• OR : Joins two or more conditions, and returns results when any
of the conditions are true.
• NOT : Negates the expression that follows it.
4. Department of Information Technology 4Data base Technologies (ITB4201)
AND OPERATOR
SELECT emp_last_name "Last Name",
emp_first_name "First Name",
emp_gender "Gender"
FROM employee
WHERE emp_gender = 'F' AND emp_last_name > ‘E'
ORDER BY emp_last_name;
Last Name First Name Gender
---------- ------------- ------
Joyner Suzanne F
Markis Marcia F
Prescott Sherri F
5. Department of Information Technology 5Data base Technologies (ITB4201)
OR OPERATOR
SELECT emp_last_name "Last Name",
emp_first_name "First Name",
emp_gender "Gender"
FROM employee
WHERE emp_gender = 'F' OR emp_last_name > 'M'
ORDER BY emp_last_name;
Last Name First Name Gender
--------------- --------------- ------
Joyner Suzanne F
Markis Marcia F
Prescott Sherri F
Zhu Waiman M
6. Department of Information Technology 6Data base Technologies (ITB4201)
NOT OPERATOR
SELECT emp_last_name "Last Name",
emp_first_name "First Name",
emp_dpt_number "Dept"
FROM employee
WHERE NOT emp_dpt_number = 7
ORDER BY emp_last_name;
Last Name First Name Dept
--------------- --------------- -----
Amin Hyder 3
Bordoloi Bijoy 1
Joyner Suzanne 3
Markis Marcia 3
7. Department of Information Technology 7Data base Technologies (ITB4201)
Combining OR and AND Operators
• When the AND operator is combined with OR,
the Oracle server will evaluate the condition
connected by the AND first before any
conditions connected with OR.
• Parenthesis must be used to force an order of
operation.
8. Department of Information Technology 8Data base Technologies (ITB4201)
Combining OR and AND Operators
SELECT emp_last_name "Last Name",
emp_first_name "First Name",
emp_dpt_number "Dept", emp_gender "Gender"
FROM employee
WHERE emp_last_name > 'E' AND emp_gender = 'F‘
OR emp_dpt_number = 1
ORDER BY emp_last_name;
Last Name First Name Dept Gender
--------------- -------------- ----- ------
Bordoloi Bijoy 1 M
Joyner Suzanne 3 F
Markis Marcia 3 F
Prescott Sherri 7 F
9. Department of Information Technology 9Data base Technologies (ITB4201)
Combining OR and AND Operators
SELECT emp_last_name "Last Name",
emp_first_name "First Name",
emp_dpt_number "Dept", emp_gender "Gender"
FROM employee
WHERE emp_last_name > 'E' AND
(emp_gender = 'F' OR emp_dpt_number = 1)
ORDER BY emp_last_name;
Last Name First Name Dept Gender
--------------- --------------- ----- ------
Joyner Suzanne 3 F
Markis Marcia 3 F
Prescott Sherri 7 F
10. Department of Information Technology 10Data base Technologies (ITB4201)
LISTS (IN AND NOT IN)
• There are two operators that are designed for testing to determine if data stored
in a table column is either in or not in a list or set of values.
• These are the IN and NOT IN operators.
• These operators greatly simplify the task of writing queries that might otherwise
require a large number of either OR logical operators or an unwieldy use of the
NOT logical operator.
11. Department of Information Technology 11Data base Technologies (ITB4201)
Using IN Operator
SELECT emp_last_name "Last Name", emp_first_name "First
Name",
emp_salary "Salary"
FROM employee
WHERE emp_salary = 43000 OR emp_salary = 30000 OR
emp_salary = 25000
ORDER BY emp_salary;
Last Name First Name Salary
--------------- --------------- -----------
Markis Marcia $25,000.00
Amin Hyder $25,000.00
Prescott Sherri $25,000.00
Bock Douglas $30,000.00
Joyner Suzanne $43,000.00
Zhu Waiman $43,000.00
6 rows selected.
12. Department of Information Technology 12Data base Technologies (ITB4201)
Using IN Operator
SELECT emp_last_name "Last Name", emp_first_name "First Name",
emp_salary "Salary"
FROM employee
WHERE emp_salary IN (43000, 30000, 25000)
ORDER BY emp_salary;
Last Name First Name Salary
--------------- --------------- -----------
Markis Marcia $25,000.00
Amin Hyder $25,000.00
Prescott Sherri $25,000.00
Bock Douglas $30,000.00
Joyner Suzanne $43,000.00
Zhu Waiman $43,000.00
6 rows selected.
13. Department of Information Technology 13Data base Technologies (ITB4201)
Using IN Operator
SELECT emp_last_name "Last Name", emp_first_name "First
Name",
emp_city "City"
FROM employee
WHERE emp_city IN ('Marina', 'Edwardsville', 'St. Louis')
ORDER BY emp_city;
Last Name First Name City
--------------- --------------- -------------
Bordoloi Bijoy Edwardsville
Prescott Sherri Edwardsville
Joyner Suzanne Marina
Amin Hyder Marina
Zhu Waiman St. Louis
Bock Douglas St. Louis
14. Department of Information Technology 14Data base Technologies (ITB4201)
Using the NOT IN Operator
• NOT can precede IN to form negative.
• To get the list of employees who did not earn the
three salary figures listed above
SELECT emp_last_name "Last Name", emp_first_name "First Name",
emp_salary "Salary"
FROM employee
WHERE emp_salary NOT IN (43000, 30000, 25000)
ORDER BY emp_salary;
Last Name First Name Salary
--------------- --------------- -----------
Joshi Dinesh $38,000.00
Bordoloi Bijoy $55,000.00
15. Department of Information Technology 15Data base Technologies (ITB4201)
RANGES (BETWEEN AND NOT BETWEEN)
• SQL provides two operators, BETWEEN and NOT BETWEEN that
can simply the range of values in a query.
• This eliminates the need to use a more complex WHERE clause
involving the use of the AND logical operator.
16. Department of Information Technology 16Data base Technologies (ITB4201)
Using the BETWEEN Operator
• The following query uses the AND logical operator.
SELECT emp_last_name "Last Name", emp_first_name "First Name",
emp_salary "Salary"
FROM employee
WHERE emp_salary >= 25000 AND emp_salary <= 40000
ORDER BY emp_salary;
Last Name First Name Salary
-------------- --------------- -----------
Markis Marcia $25,000.00
Amin Hyder $25,000.00
Prescott Sherri $25,000.00
Bock Douglas $30,000.00
Joshi Dinesh $38,000.00
17. Department of Information Technology 17Data base Technologies (ITB4201)
Using the BETWEEN Operator
• The query can be rewritten using the BETWEEN
operator.
SELECT emp_last_name "Last Name", emp_first_name "First Name",
emp_salary "Salary"
FROM employee
WHERE emp_salary BETWEEN 25000 AND 40000
ORDER BY emp_salary;
Last Name First Name Salary
--------------- --------------- -----------
Markis Marcia $25,000.00
Amin Hyder $25,000.00
Prescott Sherri $25,000.00
Bock Douglas $30,000.00
Joshi Dinesh $38,000.00
18. Department of Information Technology 18Data base Technologies (ITB4201)
Using the NOT BETWEEN Operator
SELECT emp_last_name "Last Name", emp_salary "Salary"
FROM employee
WHERE emp_salary NOT BETWEEN 28000 AND 50000
ORDER BY emp_salary;
Last Name Salary
--------------- -----------
Markis $25,000.00
Amin $25,000.00
Prescott $25,000.00
Bordoloi $55,000.00
19. Department of Information Technology 19Data base Technologies (ITB4201)
LIKE AND NOT LIKE
• The LIKE and NOT LIKE operators can be used to
search for data rows containing incomplete or partial
character strings within a data column.
• The next query searches the employee table for
employee names that begin with the characters 'Bo'.
• The search is case-sensitive meaning that 'Bo' is not
equivalent to 'BO'.
20. Department of Information Technology 20Data base Technologies (ITB4201)
LIKE AND NOT LIKE
SELECT emp_last_name "Last Name", emp_first_name "First
Name"
FROM employee
WHERE emp_last_name LIKE 'Bo%';
Last Name First Name
------------- -------------
Bordoloi Bijoy
Bock Douglas
21. Department of Information Technology 21Data base Technologies (ITB4201)
LIKE AND NOT LIKE
Wild card Meaning
% (percent)any string of zero or more characters
_ (underscore) any single character
[ ] (brackets) any single character within a specified range such as 'a' to 'd', inclusive [a-d]
or a set of characters such as [aeiouy]
[^] (not brackets) any single character not in the specified range or set.(e.g., [^a-f] )
Oracle supports only the first two,
SQL Server and Sybase supports all four.
22. Department of Information Technology 22Data base Technologies (ITB4201)
MORE EXAMPLES
• LIKE '%inger' will search for every name that ends with 'inger' (Ringer,
Stringer).
• LIKE '%en%' will search for every name that has the letters 'en' in the
name (Bennet, Green, McBadden).
• LIKE '_heryl' will search for every six-letter name ending with 'heryl'
(Cheryl). Notice how this is different than '%heryl' which would return
names that are six characters or more.
23. Department of Information Technology 23Data base Technologies (ITB4201)
MORE EXAMPLES
• LIKE '[CK]ars[eo]n' will search for every six-letter name that
begins with a 'C' or 'K' and has the letter 'e' or 'o' between 'ars'
and 'n' (e.g., 'Carsen,' 'Karsen,' 'Carson,' and 'Karson'.
• LIKE '[M-Z]inger' will search for all the names ending with 'inger'
that begin with any single letter 'M' thru 'Z' (Ringer).
• LIKE 'M[^c]%' will search for all the names that begin with 'M'
not having 'c' as the second letter.
24. Department of Information Technology 24Data base Technologies (ITB4201)
MORE EXAMPLES
The SELECT statement shown below generates a result table that includes
all DISTINCT rows where the employee social security number in the
assignment table ends with the numbers 555.
SELECT DISTINCT work_emp_ssn "Emp SSN"
FROM assignment
WHERE work_emp_ssn LIKE '%555';
Emp SSN
------------
999555555
25. Department of Information Technology 25Data base Technologies (ITB4201)
UNKNOWN VALUES
(IS NULL AND IS NOT NULL)
• NULL value is not synonymous with "zero" (numerical values) or "blank"
(character values).
• NULL values allow users to distinguish between a deliberate entry of
zero/blank and a non-entry of data.
SELECT *
FROM assignment
WHERE work_hours IS NULL;
WORK_EMP_ WORK_PRO_NUMBER WORK_HOURS
--------- --------------- ----------
999444444 1
999666666 20
26. Department of Information Technology 26Data base Technologies (ITB4201)
MORE EXAMPLES
SELECT *
FROM assignment
WHERE work_hours = 0;
no rows selected
• The query did not return a result table because none of the rows in the
assignment table have a zero value for work_hours. Thus, you can see
that zero (0) is a value, not an "unknown value."
27. Department of Information Technology 27Data base Technologies (ITB4201)
MORE EXAMPLES
• The NOT NULL condition can also be tested.
SELECT *
FROM assignment
WHERE work_hours IS NOT NULL;
15 rows selected.
• The result table contains all the rows where work_hours column
contains a value.
28. Department of Information Technology 28Data base Technologies (ITB4201)
EXPRESSIONS IN SELECT CLAUSES
• An expression is formed by combining a column name or constant with an
arithmetic operator.
• The arithmetic operators used in SQL are
SYMBOL OPERATION ORDER
* Multiplication 1
/ Division 1
% Modulo 1
+ Addition 2
- Subtraction 2
29. Department of Information Technology 29Data base Technologies (ITB4201)
MORE EXAMPLES
SELECT emp_last_name "Last Name", emp_first_name "First
Name",
emp_salary/12 "Monthly Salary"
FROM employee
WHERE emp_salary/12 > 3500
ORDER BY emp_last_name;
Last Name First Name Monthly Salary
--------------- --------------- --------------
Bordoloi Bijoy $4,583.33
Joyner Suzanne $3,583.33
Zhu Waiman $3,583.33
30. Department of Information Technology 30Data base Technologies (ITB4201)
EXPRESSIONS
• When expression is used in select with a column name it has no effect on
the table’s underlying values.
• The data contained in each column must be defined as int, smallint,
tinyint, float, money, and smallmoney.
• The result of an arithmetic operation on NULL is NULL.
31. Department of Information Technology 31Data base Technologies (ITB4201)
Examples of Operations on Nulls
Table: Compensation
EMP# JOBCODE SALARY COMMISSION
E10 SALES 12500 32090
E11 NULL 25000 8000
E12 SALES 44000 0
E13 SALES 44000 NULL
E14 PROG 19500 NULL
E15 CLERK NULL NULL
32. Department of Information Technology 32Data base Technologies (ITB4201)
Examples of Operations on Nulls
List the employees whose total earnings exceed $30000.00.
SELECTEMP#
FROM COMPENSATION
WHERE JOBCODE = “SALES”
AND (SALARY + COMMISSION) > 30000
EMP#
E10
E12
E13 is missing because?
33. Department of Information Technology 33Data base Technologies (ITB4201)
ORDER BY
• The ORDER BY clause sorts the
results of a query
– You can sort in ascending (default) or
descending order
– Multiple columns can be given
– You cannot order by a column which isn’t in
the result
SELECT <columns>
FROM <tables>
WHERE <condition>
ORDER BY <cols>
[ASCENDING |
DESCENDING|
ASC | DESC ]
34. Department of Information Technology 34Data base Technologies (ITB4201)
ORDER BY Example
Grades
Name Code Mark
John DBS 56
John IAI 72
Mary DBS 60
Mark PR1 43
Mark PR2 35
Jane IAI 54
Name Code Mark
Mark PR2 35
Mark PR1 43
Jane IAI 54
John DBS 56
Mary DBS 60
John IAI 72
SELECT * FROM Grades
ORDER BY Mark
35. Department of Information Technology 35Data base Technologies (ITB4201)
ORDER BY Example
Grades
Name Code Mark
John DBS 56
John IAI 72
Mary DBS 60
Mark PR1 43
Mark PR2 35
Jane IAI 54
Name Code Mark
Mary DBS 60
John DBS 56
John IAI 72
Jane IAI 54
Mark PR1 43
Mark PR2 35
SELECT * FROM Grades
ORDER BY Code ASC,
Mark DESC
36. Department of Information Technology 36Data base Technologies (ITB4201)
Constants and Arithmetic
• As well as column names, you can
select constants, compute arithmetic
expressions and evaluate functions in
a SELECT statement
SELECT Mark/100
FROM Grades
SELECT
Salary + Bonus
FROM Employee
SELECT 1.175*Price
FROM Products
37. Department of Information Technology 37Data base Technologies (ITB4201)
Aggregate Functions
• Aggregate functions compute
summaries of data in a table
– Most aggregate functions (all except
COUNT) work on a single column of
numeric data
– Use an alias to name the result
• Aggregate functions
– COUNT: The number of rows
– SUM: The sum of the entries in a column
– AVG: The average entry in a column
– MIN, MAX: The minimum and maximum
entries in a column
38. Department of Information Technology 38Data base Technologies (ITB4201)
Aggregate Functions
Grades
Name Code Mark
John DBS 56
John IAI 72
Mary DBS 60
Mark PR1 43
Mark PR2 35
Jane IAI 54
SELECT
COUNT(*) AS Count
FROM Grades
SELECT
SUM(Mark) AS Total
FROM Grades
SELECT
MAX(Mark) AS Best
FROM Grades
Count
6
Total
320
Best
72
39. Department of Information Technology 39Data base Technologies (ITB4201)
Aggregate Functions
• You can combine aggregate
functions using arithmetic
SELECT
MAX(Mark)-MIN(Mark)
AS Range
FROM Grades
Grades
Name Code Mark
John DBS 56
John IAI 72
Mary DBS 60
Mark PR1 43
Mark PR2 35
Jane IAI 54
Range
37
MAX(Mark) = 72
MIN(Mark) = 35
40. Department of Information Technology 40Data base Technologies (ITB4201)
Example
• Find John’s average mark, weighted by
the credits of each moduleModules
Code Title Credits
DBS Database Sys. 10
GRP Group Project 20
PRG Programming 10
Grades
Name Code Mark
John DBS 60
Mark GRP 47
Mary PRG 56
SELECT
SUM(Mark*Credits)/SUM(Credits)
FROM Modules, Grades
WHERE Modules.Code=Grades.Code
AND Grades.Name = ‘John’
41. Department of Information Technology 41Data base Technologies (ITB4201)
GROUP BY
• Sometimes we want to apply
aggregate functions to groups of rows
• Example, find the average mark of
each student
• The GROUP BY clause does this
SELECT <cols1>
FROM <tables>
GROUP BY <cols2>
42. Department of Information Technology 42Data base Technologies (ITB4201)
GROUP BY
SELECT <cols1>
FROM <tables>
GROUP BY <cols2>
• Every entry in <cols1> must be in
<cols2>, be a constant, or be an
aggregate function
• You can have WHERE or ORDER BY
clauses as well as a GROUP BY clause
43. Department of Information Technology 43Data base Technologies (ITB4201)
GROUP BY
Grades
Name Code Mark
John DBS 56
John IAI 72
Mary DBS 60
Mark PR1 43
Mark PR2 35
Jane IAI 54
SELECT Name,
AVG(Mark) AS Average
FROM Grades
GROUP BY Name
Name Average
John 64
Mary 60
Mark 39
Jane 54
44. Department of Information Technology 44Data base Technologies (ITB4201)
GROUP BY
• Find the total value of the sales for
each department in each month
– Can group by Month then Department or
Department then Month
– Same results, but in a different order
Month Department Value
March Fiction 20
March Travel 30
March Technical 40
April Fiction 10
April Fiction 30
April Travel 25
April Fiction 20
May Fiction 20
May Technical 50
Sales
45. Department of Information Technology 45Data base Technologies (ITB4201)
GROUP BY
Month Department Total
April Fiction 60
April Travel 25
March Fiction 20
March Technical 40
March Travel 30
May Fiction 20
May Technical 50
SELECT Month, Department,
SUM(Value) AS Total
FROM Sales
GROUP BY Month, Department
Month Department Total
April Fiction 60
March Fiction 20
May Fiction 20
March Technical 40
May Technical 50
April Travel 25
March Travel 30
SELECT Month, Department,
SUM(Value) AS Total
FROM Sales
GROUP BY Department, Month
46. Department of Information Technology 46Data base Technologies (ITB4201)
HAVING
• HAVING is like a WHERE clause, except
that it applies to the results of a
GROUP BY query
• It can be used to select groups which
satisfy a given condition
SELECT Name,
AVG(Mark) AS Average
FROM Grades
GROUP BY Name
HAVING AVG(Mark) >= 40
Name Average
John 64
Mary 60
Jane 54
47. Department of Information Technology 47Data base Technologies (ITB4201)
WHERE and HAVING
• WHERE refers to the rows of tables,
and so cannot use aggregate functions
• HAVING refers to the groups of rows,
and so cannot use columns which are
not in the GROUP BY
• Think of a query being processed as
follows:
• Tables are combined
• WHERE clauses
• GROUP BY and Aggregates
• Column selection
• HAVING clauses
• ORDER BY
48. Department of Information Technology 48Data base Technologies (ITB4201)
UNION, etc.
• UNION, INTERSECT, and EXCEPT
– These treat the tables as sets and are the
usual set operators of union, intersection,
and difference
– We’ll concentrate on UNION
– Oracle has MINUS instead of EXCEPT
• They all combine the results from two
select statements
• The results of the two selects must
have the same columns and data types
49. Department of Information Technology 49Data base Technologies (ITB4201)
UNION
• Find, in a single query, the average
mark for each student, and the
average mark overallGrades
Name Code Mark
Jane IAI 52
John DBS 56
John IAI 72
Mark PR1 43
Mark PR2 35
Mary DBS 60
50. Department of Information Technology 50Data base Technologies (ITB4201)
UNION
• The average for each
student:
SELECT Name,
AVG(Mark) AS Average
FROM Grades
GROUP BY Name
• The average overall
SELECT
‘Total’ AS Name,
AVG(Mark) AS Average
FROM Grades
• Note - this has the same
columns as the average by
student
51. Department of Information Technology 51Data base Technologies (ITB4201)
UNION
SELECT Name
AVG(Mark) AS Average
FROM Grades
GROUP BY Name
UNION
SELECT
'Total' as Name,
AVG(Mark) AS Average
FROM Grades
Name Average
Jane 52
John 64
Mark 39
Mary 60
Total 53
52. Department of Information Technology 52Data base Technologies (ITB4201)
Tables for the Example
Student
ID First Last Year
Module
Code Title Credits
Grade
ID Code Mark YearTaken
53. Department of Information Technology 53Data base Technologies (ITB4201)
We’ll Need a UNION
• Finalists are treated differently
– Write one query for the finalists
– Write a second query for the first and
second years
– Use a UNION to join them together
<QUERY FOR FINALISTS>
UNION
<QUERY FOR OTHERS>
54. Department of Information Technology 54Data base Technologies (ITB4201)
We’ll need to Join the Tables
• Both of the subqueries need
information from all the tables
– The student ID, name and year
– The marks for each module and the year
taken
– The number of credits for each module
• This is a natural join operation
– We could use a NATURAL JOIN statement,
and hope that our version of SQL can do it
– Safer to just use a WHERE clause
55. Department of Information Technology 55Data base Technologies (ITB4201)
The Query So Far
SELECT <some information>
FROM Student, Module, Grade
WHERE Student.ID = Grade.ID
AND Module.Code = Grade.Code
AND <student is in third year>
UNION
SELECT <some information>
FROM Student, Module, Grade
WHERE Student.ID = Grade.ID
AND Module.Code = Grade.Code
AND <student is in first or second year>
56. Department of Information Technology 56Data base Technologies (ITB4201)
Information for Finalists
•We need to retrieve
– Compute average mark, weighted 40-60
across years 2 and 3
– First year marks need to be ignored
– The ID, Name, and Year are needed as they
are used for ordering
• The average is hard
– We don’t have any statement to separate
years 2 and 3 easily
– We can exploit the fact that 40 = 20*2 and
60 = 20*3, so YearTaken and the weighting
have a simple relationship
57. Department of Information Technology 57Data base Technologies (ITB4201)
Information for Finalists
SELECT Year, Student.ID, Last, First,
SUM((20*YearTaken/100)*Mark*Credits)/120
AS AverageMark
FROM Student, Module, Grade
WHERE Student.ID = Grade.ID
AND Module.Code = Grade.Code
AND YearTaken IN (2,3)
AND Year = 3
GROUP BY Year, Student.ID, First, Last
58. Department of Information Technology 58Data base Technologies (ITB4201)
Information for Other Students
• Other students are easier than finalists
– We just need to average their marks where YearTaken and Year are
the same
– As before we need the ID, Name, and Year for ordering
59. Department of Information Technology 59Data base Technologies (ITB4201)
Information for Other Students
SELECT Year, Student.ID, Last, First,
SUM(Mark*Credits)/120 AS AverageMark
FROM Student, Module, Grade
WHERE Student.ID = Grade.ID
AND Module.Code = Grade.Code
AND YearTaken = Year
AND Year IN (1,2)
GROUP BY Year, Student.ID, First, Last
60. Department of Information Technology 60Data base Technologies (ITB4201)
The Final Query
SELECT Year, Student.ID, Last, First,
SUM((20*YearTaken/100)*Mark*Credits)/120 AS AverageMark
FROM Student, Module, Grade
WHERE Student.ID = Grade.ID AND Module.Code = Grade.Code
AND YearTaken IN (2,3) AND Year = 3
GROUP BY Year, Student.ID, First, Last
UNION
SELECT Year, Student.ID, Last, First,
SUM(Mark*Credits)/120 AS AverageMark
FROM Student, Module, Grade
WHERE Student.ID = Grade.ID AND Module.Code = Grade.Code
AND YearTaken = Year AND Year IN (1,2)
GROUP BY Year, Student.ID, First, Last
ORDER BY Year desc, AverageMark desc, First, Last, ID
61. Department of Information Technology 61Data base Technologies (ITB4201)
Tutorial https://www.techonthenet.com/sql/select.php