This document provides an overview of SQL and relational database concepts. It begins with a brief history of SQL and standards. It then covers data definition language to define database schemas, basic query structure using SELECT, FROM, and WHERE clauses, and additional SQL features like joins, null values, aggregate functions, and modifying databases. It provides examples of creating tables, inserting and deleting data, and performing various types of queries.
The document introduces common data types in SQL such as char, varchar, int, numeric, and date. It describes how to create databases and tables using SQL statements like CREATE DATABASE, CREATE TABLE, INSERT INTO, and ALTER TABLE. It also covers SQL queries using SELECT, FROM, WHERE, ORDER BY, LIKE and other clauses to retrieve and filter data from one or more tables.
This document provides an overview of relational database systems and concepts. It defines key terms like relation schema, relation instance, attributes, tuples, keys, database schema, and database instance. It describes schema diagrams and relational query languages like relational algebra. The core relational algebra operations of select, project, join, union, difference, and rename are explained. The document provides examples of how to represent a database schema and write queries using these operations.
This document provides an overview of SQL (Structured Query Language) including its history, data definition and manipulation capabilities. Key topics covered include SQL's data types, basic queries using SELECT, FROM and WHERE clauses, joins, aggregation, null values, triggers and indexes. The document also discusses SQL standards over time and commercial database implementations of SQL features.
This document discusses relational database management systems and SQL. It covers basic SQL queries involving selection, projection, and joins. It also discusses set operations in SQL like union, intersect, and except. Further, it describes complex queries, integrity constraints, domains, and data definition language commands for creating, altering, and dropping tables.
This document provides a summary of the basic structure and key concepts of SQL, including:
1) SQL queries typically involve a SELECT statement to retrieve attributes from one or more relations based on conditions in a WHERE clause.
2) Common SQL clauses include SELECT, FROM, WHERE, GROUP BY, HAVING, and aggregate functions are used to perform calculations on groups of records.
3) Null values, three valued logic, and handling of duplicates are important concepts when working with SQL queries and relations.
The document discusses SQL SELECT statements and their capabilities. It explains how to write basic SELECT statements to retrieve data from one or more tables, including selecting specific columns, filtering rows, sorting results, and performing calculations. It also covers JOIN operations, including inner joins to combine data from multiple tables and self joins to join a table to itself.
The document discusses SQL SELECT statements and their capabilities. It explains how to write basic SELECT statements to retrieve data from one or more tables, including selecting specific columns, filtering rows, sorting results, and performing calculations. It also covers JOIN operations, including inner joins to combine data from multiple tables and self joins to join a table to itself.
This document provides an overview of querying and reporting in SQL, covering topics like arithmetic operators, built-in functions, selecting data, grouping results, joins, and subqueries. The agenda includes learning objectives, descriptions of SELECT statements, and explanations of concepts like aggregate functions, limiting results, sorting data, and correlating subqueries.
This document provides an overview of SQL and relational database concepts. It describes the history and standards of SQL, data definition and domain types in SQL, basic query structure including the SELECT, FROM, and WHERE clauses, and DML operations like INSERT, DELETE, and ALTER TABLE. Examples of table schemas and queries involving joins, aggregation, and renaming are provided to illustrate SQL syntax and capabilities.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. The chapter introduces SQL, including its history, data definition language, data types, basic query structure using SELECT, FROM, and WHERE clauses, and additional query capabilities like aggregation, subqueries and string operations. It also covers modifying the database using INSERT, DELETE, ALTER and DROP statements.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. It discusses the history and standards of SQL, the data definition language for creating tables with attributes and constraints, basic query structure using SELECT, FROM, and WHERE clauses, and examples of joins, renaming, and self joins.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. It introduces SQL, covering its history, data definition language, data types, CREATE TABLE statement, integrity constraints, updating tables, basic query structure using SELECT, FROM, and WHERE clauses, and examples of joins, renaming, and self joins.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. The chapter introduces SQL, including its history, data definition language, data types, basic query structure using SELECT, FROM, and WHERE clauses, and additional query capabilities like aggregation, subqueries, string operations and more. Examples are provided throughout to illustrate SQL concepts and syntax.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. It introduces SQL, covering its history, data definition language, data types, CREATE TABLE statement, integrity constraints, updating tables, basic query structure using SELECT, FROM, and WHERE clauses, and examples of joins, renaming, and self joins.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. The chapter introduces SQL, including its history, data definition language, data types, basic query structure using SELECT, FROM, and WHERE clauses, and additional query capabilities like aggregation, subqueries and string operations. The document is made up of multiple slides that cover these SQL topics at a high-level.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 7th Ed." by Silberschatz, Korth and Sudarshan. It covers the history and components of SQL, data definition and manipulation languages, basic query structure, predicates, null values, and set operations in SQL. Key topics include the CREATE TABLE statement, data types, integrity constraints, SELECT statements, joins, ordering results, and aggregate functions.
This document provides an overview of the relational model for databases. It discusses how data is organized in tables called relations and how the tables are related to each other. The key aspects covered include how the relational model was introduced, how relations represent data as tables with rows and columns, properties of relations like primary keys, and relational algebra operations like select, project, join, union and more.
Value Stream Mapping Worskshops for Intelligent Continuous SecurityMarc Hornbeek
This presentation provides detailed guidance and tools for conducting Current State and Future State Value Stream Mapping workshops for Intelligent Continuous Security.
We introduce the Gaussian process (GP) modeling module developed within the UQLab software framework. The novel design of the GP-module aims at providing seamless integration of GP modeling into any uncertainty quantification workflow, as well as a standalone surrogate modeling tool. We first briefly present the key mathematical tools on the basis of GP modeling (a.k.a. Kriging), as well as the associated theoretical and computational framework. We then provide an extensive overview of the available features of the software and demonstrate its flexibility and user-friendliness. Finally, we showcase the usage and the performance of the software on several applications borrowed from different fields of engineering. These include a basic surrogate of a well-known analytical benchmark function; a hierarchical Kriging example applied to wind turbine aero-servo-elastic simulations and a more complex geotechnical example that requires a non-stationary, user-defined correlation function. The GP-module, like the rest of the scientific code that is shipped with UQLab, is open source (BSD license).
Ad
More Related Content
Similar to SQL data types: INT, VARCHAR, CHAR,.pptx (20)
This document discusses relational database management systems and SQL. It covers basic SQL queries involving selection, projection, and joins. It also discusses set operations in SQL like union, intersect, and except. Further, it describes complex queries, integrity constraints, domains, and data definition language commands for creating, altering, and dropping tables.
This document provides a summary of the basic structure and key concepts of SQL, including:
1) SQL queries typically involve a SELECT statement to retrieve attributes from one or more relations based on conditions in a WHERE clause.
2) Common SQL clauses include SELECT, FROM, WHERE, GROUP BY, HAVING, and aggregate functions are used to perform calculations on groups of records.
3) Null values, three valued logic, and handling of duplicates are important concepts when working with SQL queries and relations.
The document discusses SQL SELECT statements and their capabilities. It explains how to write basic SELECT statements to retrieve data from one or more tables, including selecting specific columns, filtering rows, sorting results, and performing calculations. It also covers JOIN operations, including inner joins to combine data from multiple tables and self joins to join a table to itself.
The document discusses SQL SELECT statements and their capabilities. It explains how to write basic SELECT statements to retrieve data from one or more tables, including selecting specific columns, filtering rows, sorting results, and performing calculations. It also covers JOIN operations, including inner joins to combine data from multiple tables and self joins to join a table to itself.
This document provides an overview of querying and reporting in SQL, covering topics like arithmetic operators, built-in functions, selecting data, grouping results, joins, and subqueries. The agenda includes learning objectives, descriptions of SELECT statements, and explanations of concepts like aggregate functions, limiting results, sorting data, and correlating subqueries.
This document provides an overview of SQL and relational database concepts. It describes the history and standards of SQL, data definition and domain types in SQL, basic query structure including the SELECT, FROM, and WHERE clauses, and DML operations like INSERT, DELETE, and ALTER TABLE. Examples of table schemas and queries involving joins, aggregation, and renaming are provided to illustrate SQL syntax and capabilities.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. The chapter introduces SQL, including its history, data definition language, data types, basic query structure using SELECT, FROM, and WHERE clauses, and additional query capabilities like aggregation, subqueries and string operations. It also covers modifying the database using INSERT, DELETE, ALTER and DROP statements.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. It discusses the history and standards of SQL, the data definition language for creating tables with attributes and constraints, basic query structure using SELECT, FROM, and WHERE clauses, and examples of joins, renaming, and self joins.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. It introduces SQL, covering its history, data definition language, data types, CREATE TABLE statement, integrity constraints, updating tables, basic query structure using SELECT, FROM, and WHERE clauses, and examples of joins, renaming, and self joins.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. The chapter introduces SQL, including its history, data definition language, data types, basic query structure using SELECT, FROM, and WHERE clauses, and additional query capabilities like aggregation, subqueries, string operations and more. Examples are provided throughout to illustrate SQL concepts and syntax.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. It introduces SQL, covering its history, data definition language, data types, CREATE TABLE statement, integrity constraints, updating tables, basic query structure using SELECT, FROM, and WHERE clauses, and examples of joins, renaming, and self joins.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 6th Ed." by Silberschatz, Korth and Sudarshan. The chapter introduces SQL, including its history, data definition language, data types, basic query structure using SELECT, FROM, and WHERE clauses, and additional query capabilities like aggregation, subqueries and string operations. The document is made up of multiple slides that cover these SQL topics at a high-level.
This document provides an overview of Chapter 3 from the textbook "Database System Concepts, 7th Ed." by Silberschatz, Korth and Sudarshan. It covers the history and components of SQL, data definition and manipulation languages, basic query structure, predicates, null values, and set operations in SQL. Key topics include the CREATE TABLE statement, data types, integrity constraints, SELECT statements, joins, ordering results, and aggregate functions.
This document provides an overview of the relational model for databases. It discusses how data is organized in tables called relations and how the tables are related to each other. The key aspects covered include how the relational model was introduced, how relations represent data as tables with rows and columns, properties of relations like primary keys, and relational algebra operations like select, project, join, union and more.
Value Stream Mapping Worskshops for Intelligent Continuous SecurityMarc Hornbeek
This presentation provides detailed guidance and tools for conducting Current State and Future State Value Stream Mapping workshops for Intelligent Continuous Security.
We introduce the Gaussian process (GP) modeling module developed within the UQLab software framework. The novel design of the GP-module aims at providing seamless integration of GP modeling into any uncertainty quantification workflow, as well as a standalone surrogate modeling tool. We first briefly present the key mathematical tools on the basis of GP modeling (a.k.a. Kriging), as well as the associated theoretical and computational framework. We then provide an extensive overview of the available features of the software and demonstrate its flexibility and user-friendliness. Finally, we showcase the usage and the performance of the software on several applications borrowed from different fields of engineering. These include a basic surrogate of a well-known analytical benchmark function; a hierarchical Kriging example applied to wind turbine aero-servo-elastic simulations and a more complex geotechnical example that requires a non-stationary, user-defined correlation function. The GP-module, like the rest of the scientific code that is shipped with UQLab, is open source (BSD license).
ELectronics Boards & Product Testing_Shiju.pdfShiju Jacob
This presentation provides a high level insight about DFT analysis and test coverage calculation, finalizing test strategy, and types of tests at different levels of the product.
The role of the lexical analyzer
Specification of tokens
Finite state machines
From a regular expressions to an NFA
Convert NFA to DFA
Transforming grammars and regular expressions
Transforming automata to grammars
Language for specifying lexical analyzers
Concept of Problem Solving, Introduction to Algorithms, Characteristics of Algorithms, Introduction to Data Structure, Data Structure Classification (Linear and Non-linear, Static and Dynamic, Persistent and Ephemeral data structures), Time complexity and Space complexity, Asymptotic Notation - The Big-O, Omega and Theta notation, Algorithmic upper bounds, lower bounds, Best, Worst and Average case analysis of an Algorithm, Abstract Data Types (ADT)
International Journal of Distributed and Parallel systems (IJDPS)samueljackson3773
The growth of Internet and other web technologies requires the development of new
algorithms and architectures for parallel and distributed computing. International journal of
Distributed and parallel systems is a bimonthly open access peer-reviewed journal aims to
publish high quality scientific papers arising from original research and development from
the international community in the areas of parallel and distributed systems. IJDPS serves
as a platform for engineers and researchers to present new ideas and system technology,
with an interactive and friendly, but strongly professional atmosphere.
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYijscai
With the increased use of Artificial Intelligence (AI) in malware analysis there is also an increased need to
understand the decisions models make when identifying malicious artifacts. Explainable AI (XAI) becomes
the answer to interpreting the decision-making process that AI malware analysis models use to determine
malicious benign samples to gain trust that in a production environment, the system is able to catch
malware. With any cyber innovation brings a new set of challenges and literature soon came out about XAI
as a new attack vector. Adversarial XAI (AdvXAI) is a relatively new concept but with AI applications in
many sectors, it is crucial to quickly respond to the attack surface that it creates. This paper seeks to
conceptualize a theoretical framework focused on addressing AdvXAI in malware analysis in an effort to
balance explainability with security. Following this framework, designing a machine with an AI malware
detection and analysis model will ensure that it can effectively analyze malware, explain how it came to its
decision, and be built securely to avoid adversarial attacks and manipulations. The framework focuses on
choosing malware datasets to train the model, choosing the AI model, choosing an XAI technique,
implementing AdvXAI defensive measures, and continually evaluating the model. This framework will
significantly contribute to automated malware detection and XAI efforts allowing for secure systems that
are resilient to adversarial attacks.
its all about Artificial Intelligence(Ai) and Machine Learning and not on advanced level you can study before the exam or can check for some information on Ai for project
The Fluke 925 is a vane anemometer, a handheld device designed to measure wind speed, air flow (volume), and temperature. It features a separate sensor and display unit, allowing greater flexibility and ease of use in tight or hard-to-reach spaces. The Fluke 925 is particularly suitable for HVAC (heating, ventilation, and air conditioning) maintenance in both residential and commercial buildings, offering a durable and cost-effective solution for routine airflow diagnostics.
☁️ GDG Cloud Munich: Build With AI Workshop - Introduction to Vertex AI! ☁️
Join us for an exciting #BuildWithAi workshop on the 28th of April, 2025 at the Google Office in Munich!
Dive into the world of AI with our "Introduction to Vertex AI" session, presented by Google Cloud expert Randy Gupta.
π0.5: a Vision-Language-Action Model with Open-World GeneralizationNABLAS株式会社
今回の資料「Transfusion / π0 / π0.5」は、画像・言語・アクションを統合するロボット基盤モデルについて紹介しています。
拡散×自己回帰を融合したTransformerをベースに、π0.5ではオープンワールドでの推論・計画も可能に。
This presentation introduces robot foundation models that integrate vision, language, and action.
Built on a Transformer combining diffusion and autoregression, π0.5 enables reasoning and planning in open-world settings.
Raish Khanji GTU 8th sem Internship Report.pdfRaishKhanji
This report details the practical experiences gained during an internship at Indo German Tool
Room, Ahmedabad. The internship provided hands-on training in various manufacturing technologies, encompassing both conventional and advanced techniques. Significant emphasis was placed on machining processes, including operation and fundamental
understanding of lathe and milling machines. Furthermore, the internship incorporated
modern welding technology, notably through the application of an Augmented Reality (AR)
simulator, offering a safe and effective environment for skill development. Exposure to
industrial automation was achieved through practical exercises in Programmable Logic Controllers (PLCs) using Siemens TIA software and direct operation of industrial robots
utilizing teach pendants. The principles and practical aspects of Computer Numerical Control
(CNC) technology were also explored. Complementing these manufacturing processes, the
internship included extensive application of SolidWorks software for design and modeling tasks. This comprehensive practical training has provided a foundational understanding of
key aspects of modern manufacturing and design, enhancing the technical proficiency and readiness for future engineering endeavors.
In tube drawing process, a tube is pulled out through a die and a plug to reduce its diameter and thickness as per the requirement. Dimensional accuracy of cold drawn tubes plays a vital role in the further quality of end products and controlling rejection in manufacturing processes of these end products. Springback phenomenon is the elastic strain recovery after removal of forming loads, causes geometrical inaccuracies in drawn tubes. Further, this leads to difficulty in achieving close dimensional tolerances. In the present work springback of EN 8 D tube material is studied for various cold drawing parameters. The process parameters in this work include die semi-angle, land width and drawing speed. The experimentation is done using Taguchi’s L36 orthogonal array, and then optimization is done in data analysis software Minitab 17. The results of ANOVA shows that 15 degrees die semi-angle,5 mm land width and 6 m/min drawing speed yields least springback. Furthermore, optimization algorithms named Particle Swarm Optimization (PSO), Simulated Annealing (SA) and Genetic Algorithm (GA) are applied which shows that 15 degrees die semi-angle, 10 mm land width and 8 m/min drawing speed results in minimal springback with almost 10.5 % improvement. Finally, the results of experimentation are validated with Finite Element Analysis technique using ANSYS.
2. Domain Types in SQL
• char(n) - Fixed length character string, with user-specified length
n.
• varchar(n) - Variable length character strings, with user-specified
maximum length n.
• int - Integer (a finite subset of the integers that is machine-
dependent).
• Smallint - Small integer (a machine-dependent subset of the
integer domain type).
• numeric(p,d) - Fixed point number, with user-specified precision
of p digits, with d digits to the right of decimal point.
(ex., numeric(3,1), allows 44.5 to be stores exactly, but not 444.5
or 0.32)
• real, double precision - Floating point and double-precision
floating point numbers, with machine-dependent precision.
• float(n) - Floating point number, with user-specified precision of
at least n digits.
4. Create Table Construct
• An SQL relation is defined using the create table command:
create table r
(A1 D1, A2 D2, ..., An Dn,
(integrity-constraint1),
...,
(integrity-constraintk))
– r is the name of the relation
– each Ai is an attribute name in the schema of relation r
– Di is the data type of values in the domain of attribute Ai
• Example:
create table instructor (
ID char(5),
name varchar(20),
dept_name varchar(20),
salary numeric(8,2))
5. Integrity Constraints in Create Table:
• Types of integrity constraints
– primary key (A1, ..., An )
– foreign key (Am, ..., An ) references r
– not null
– Check Costraint
– Unique Constraint
• SQL prevents any update to the database that violates an integrity
constraint.
• Example:
create table instructor (
ID int,
name varchar(20) not null,
dept_name varchar(20),
salary int,
primary key (ID),
foreign key (dept_name) references department);
6. And a Few More Relation Definitions
• create table student (
ID varchar(5),
name varchar(20) not null,
dept_name varchar(20),
tot_cred numeric(3,0),
primary key (ID),
foreign key (dept_name) references
department);
8. Referential Integrity
• The Value appears in one relation(referencing
relation) for a given set of attributes also
appears for a certain set of attributes in
another relation(referenced relation) .Such
conditions are called referential integrity
constraints and foreign keys are a form of a
referential integrity constraints.
9. • Unique constraint
Unique ( A1, ..., An ) -No two tuples in the relation can be
equal on all the listed attributes
• Check constraint
Checks(P)- Specifies a predicate P that must be satisfied by every
tuple in a relation
create table instructor (
ID int,
name varchar(20) not null,
dept_name varchar(20),
salary int check (salary > 50000),
primary key (ID),
foreign key (dept_name) references department);
• Assigning names to constraints
salary int ,constraint minsalary check (salary > 50000)
• Drop Constraint-alter table instructor drop constraint minsalary;
11. Basic Query Structure
• A typical SQL query has the form:
select A1, A2, ..., An
from r1, r2, ..., rm
where P
– Ai represents an attribute
– Ri represents a relation
– P is a predicate.
• The result of an SQL query is a relation.
12. The select Clause
• The select clause lists the attributes desired in
the result of a query
– corresponds to the projection operation of the
relational algebra
• Example: find the names of all instructors:
select name
from instructor
• NOTE: SQL names are case insensitive (i.e., you
may use upper- or lower-case letters.)
– E.g., Name ≡ NAME ≡ name
13. The select Clause (Cont.)
• SQL allows duplicates in relations as well as in query results.
• To force the elimination of duplicates, insert the keyword
distinct after select.
• Find the department names of all instructors, and remove
duplicates
select distinct dept_name
from instructor
• The keyword all specifies that duplicates should not
be removed.
select all dept_name
from instructor
14. The select Clause (Cont.)
• An asterisk in the select clause denotes “all
attributes”
select *
from instructor
15. The select Clause (Cont.)
• The select clause can contain arithmetic expressions
involving the operation, +, –, *, and /, and operating
on constants or attributes of tuples.
– The query:
select ID, name, salary/12
from instructor
would return a relation that is the same as the instructor
relation, except that the value of the attribute salary is
divided by 12.
– Can rename “salary/12” using the as clause:
select ID, name, salary/12 as monthly_salary
16. The where Clause
• The where clause specifies conditions that the result must satisfy
– Corresponds to the selection predicate of the relational algebra.
• To find all instructors in Comp. Sci. dept
select name
from instructor
where dept_name = 'Comp. Sci.'
• SQL allows the use of the logical connectives and, or, and not
• The operands of the logical connectives can be expressions
involving the comparison operators <, <=, >, >=, =, and <>.
• Comparisons can be applied to results of arithmetic expressions
• To find all instructors in Comp. Sci. dept with salary > 70000
select name
from instructor
where dept_name = 'Comp. Sci.' and salary > 70000
17. Where Clause Predicates
• SQL includes a between comparison operator
• Example: Find the names of all instructors with
salary between $90,000 and $100,000 (that is, ≥
$90,000 and ≤ $100,000)
select name
from instructor
where salary between 90000 and 100000
• Tuple comparison
select name, course_id
from instructor, teaches (Cartesian Product(instructor X teaches))
where (instructor.ID, dept_name) = (teaches.ID,
'Biology');
19. The from Clause
• The from clause lists the relations involved in the query
– Corresponds to the Cartesian product operation of the
relational algebra.
• Find the Cartesian product (instructor X teaches)
select *
from instructor, teaches
– generates every possible instructor – teaches pair, with all
attributes from both relations.
– For common attributes (e.g., ID), the attributes in the resulting
table are renamed using the relation name (e.g., instructor.ID)
• Cartesian product not very useful directly, but useful
combined with where-clause condition (selection
operation in relational algebra).
22. Examples
• Find the names of all instructors
who have taught some course
and the course_id
select name, course_id
from instructor , teaches
where instructor.ID = teaches.ID
23. •Find the names of all instructors in the Art
department who have taught some course
and the course_id
select name, course_id
from instructor , teaches
where instructor.ID = teaches.ID
and instructor. dept_name = 'Art'
25. The Rename Operation
• The SQL allows renaming relations and attributes using the as
clause:
old-name as new-name
• Find the names of all instructors who have a higher salary than
some instructor in 'Comp. Sci'.
select distinct T.name
from instructor as T, instructor as S
where T.salary > S.salary and S.dept_name = 'Comp. Sci.’
T&S copies of instructor(aliases).T and S is called Correlation
name
Above Question Rewritten as “Find the name of all instructors who earn more
than the lowest paid instructor in Comp. Sci dept”
• Keyword as is optional and may be omitted
instructor as T ≡ instructor T
26. String Operations
• SQL includes a string-matching operator for comparisons on
character strings. The operator like uses patterns that are
described using two special characters:
– percent ( % ) The % character matches any substring
– underscore ( _ ) The _ character matches any character
• Find the names of all instructors whose name includes the
substring “dar”
select name
from instructor
where name like '%nivas%'
• Match the string “100%”
like ‘abc %' 🡪 beginning with ”abc” escape ''
like ‘abcd%’ beginning with
🡪 ”abcd”
in that above we use backslash () as the escape character
27. String Operations (Cont.)
• Patterns are case sensitive.
• Pattern matching examples:
– 'Intro%' matches any string beginning with “Intro”.
– '%Comp%' matches any string containing “Comp” as
a substring.
– '_ _ _' matches any string of exactly three
characters.
– '_ _ _ %' matches any string of at least three
characters.
28. Ordering the Display of Tuples
• List in alphabetic order the names of all instructors
select distinct name
from instructor
order by name
• We may specify desc for descending order or asc
for ascending order, for each attribute; ascending
order is the default.
– Example: order by name desc
• Can sort on multiple attributes
– Example: order by dept_name, name
29. Set Operations
• Find courses that ran in Fall 2017 or in Spring 2018
(select course_id from section where sem = 'Fall' and year = 2017)
union
(select course_id from section where sem = 'Spring' and year = 2018)
• Find courses that ran in Fall 2017 and in Spring
2018
(select course_id from section where sem = 'Fall' and year = 2017)
intersect
(select course_id from section where sem = 'Spring' and year = 2018)
• Find courses that ran in Fall 2017 but not in Spring
2018
(select course_id from section where sem = 'Fall' and year = 2017)
except
(select course_id from section where sem = 'Spring' and year = 2018)
31. Set Operations (Cont.)
• Set operations union, intersect, and except
– Each of the above operations automatically
eliminates duplicates
• To retain all duplicates use the
– union all,
– intersect all
– except all.
32. Null Values
• It is possible for tuples to have a null value, denoted by
null, for some of their attributes
• null signifies an unknown value or that a value does not
exist.
• The result of any arithmetic expression involving null is
null
– Example: 5 + null returns null
• The predicate is null can be used to check for null
values.
– Example: Find all instructors whose salary is null.
select name
from instructor
where salary is null
34. Aggregate Functions
• These functions operate on the multiset of
values of a column of a relation, and return a
value
avg: average value
min: minimum value
max: maximum value
sum: sum of values
count: number of values
35. Aggregate Functions Examples
• Find the average salary of instructors in the
Computer Science department
– select avg (salary)
from instructor
where dept_name= 'Comp. Sci.';
• Find the total number of instructors who teach a
course in the Spring 2018 semester
– select count (distinct ID)
from teaches
where semester = 'Spring' and year = 2018;
• Find the number of tuples in the course relation
– select count (*)
from course;
36. Aggregate Functions – Group By
• Find the average salary of instructors in each department
– select dept_name, avg (salary) as avg_salary
from instructor
group by dept_name;
37. Aggregate Functions – Having Clause
• Find the names and average salaries of all
departments whose average salary is greater than
42000
• Note: predicates in the having clause are applied
after the formation of groups whereas predicates
in the where clause are applied before forming
groups
select dept_name, avg (salary) as avg_salary
from instructor
group by dept_name
having avg (salary) > 42000;