SQL From Zero To Data Hero
SQL From Zero To Data Hero
BY KIRAN VARPE
BY KIRAN VARPE
Introduction to SQL
• What is SQL
• It’s applications
• SQL v/s NoSQL
• Types of SQL Commands
• What is Database
• Excel v/s Database in SQL
BY KIRAN VARPE
What IS SQL ?
BY KIRAN VARPE
SQL APPLICATION
BY KIRAN VARPE
There are mainly 3 types of SQL commands:
BY KIRAN VARPE
What is Database?
BY KIRAN VARPE
BY KIRAN VARPE
RDBMS
Database Structure
Example
BY KIRAN VARPE
• Data types
• Primary & Foreign keys
• Constraints
• SQL Commands
o CREATE
o INSERT
o UPDATE
o BACKUP
o DELETE
o ALTER
o DROP, TRUNCATE
BY KIRAN VARPE
Commonly Used data types in SQL:
BY KIRAN VARPE
Primary key (PK):
• A Primary key is a unique column
we set in a table to easily identify
and locate data in queries
• A table can have only one primary
key, which should be unique and
NOT NULL
BY KIRAN VARPE
Constraints
BY KIRAN VARPE
BY KIRAN VARPE
BY KIRAN VARPE
BY KIRAN VARPE
BY KIRAN VARPE
Operators in SQL
The SQL reserved words and characters are called
operators, which areused with a WHERE clause in
a SQL query
Most used operators:
• Arithmetic operators: arithmetic operations on
numeric values
Example: Addition (+),
Subtraction (-),
Multiplication (*), Division
(/), Modulus (%)
• Comparison operators: compare two
different data of SQL table
Example: Equal (=), Not
Equal (!=), Greater Than
(>), Greater Than Equals
to (>=)
• Logical operators: perform the Boolean operations
Example: ALL, IN, BETWEEN, LIKE, AND,
OR, NOT, ANY
• Bitwise operators: perform the bit operations on the
Integer values
Example: Bitwise AND (&), Bitwise OR(|)
BY KIRAN VARPE
BY KIRAN VARPE
Most Used String Functions are
String functions are used to perform an operation
on input string andreturn an output string
BY KIRAN VARPE
BY KIRAN VARPE
Most used Aggregate Functions are
BY KIRAN VARPE
BY KIRAN VARPE
BY KIRAN VARPE
BY KIRAN VARPE
The TIMESTAMP data type is used for
values thatcontain both date and time
parts
• TIME contains only time, format
HH:MI:SS
• DATE contains on date, format YYYY-MM-DD
• YEAR contains on year, format YYYY or YY
• TIMESTAMP contains date and time,
format YYYY-MM-DDHH:MI:SS
• TIMESTAMPTZ contains date, time and time zone
BY KIRAN VARPE
BY KIRAN VARPE
JOIN
• JOIN means to combine something.
• A JOIN clause is used to combine data
from two or more tables, based on a
related column between them.
BY KIRAN VARPE
Database
payment
customer_id
amount
customer mode
customer_id Payment_date
first_name
last_name country
address_id address city_id
city
address_id country
address city_id
postal_code
phone
BY KIRAN VARPE
TYPES OF JOINS
INNER JOIN
LEFT JOIN
RIGHT JOIN
BY KIRAN VARPE
FULL JOIN
SELF JOIN
BY KIRAN VARPE
BY KIRAN VARPE
BY KIRAN VARPE
Sub Query Example
Question: Find the details of customers,
whose payment amount is more than the
average of total amount paid by allcustomers
BY KIRAN VARPE
BY KIRAN VARPE
Window Function
Give output one row per aggregation The rows maintain their separate identities
BY KIRAN VARPE
Window Function Types
BY KIRAN VARPE
Aggregation Function Example
NOTE: Above we have used: “ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED
FOLLOWING” which will give a SINGLE output based on all INPUT Values/Partitions(if used)
BY KIRAN VARPE
Ranking Function Example
BY KIRAN VARPE
BY KIRAN VARPE
• The CASE expression goes through
conditions and returnsa value when the first
condition is met (like if-then-else
statement). If no conditions are true, it
returns the value in the ELSE clause.
• If there is no ELSE part and no
conditions are true, itreturns NULL.
• Also called CASE STATEMENT
BY KIRAN VARPE
BY KIRAN VARPE