SQL CS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Bhushan Mamtani

Simplifying Data Analytics

SQL CHEETSHEET
Categories: Common Commands Operators
DDL: Data Definition Language Data Retrieval: Data Manipulation:
Arithmetic Bitwise
DQL: Data Query Language SELECT SUBSTRING()
+-*/% & | ^ ~ << >>
DML: Data Manipulation Language FROM UPPER()
DCL: Data Control Language LOWER()
Comparison Compound
TCL: Transaction Control Language Data Filtering: LENGTH()
= <> < > <= >= = <> < > <= >=
WHERE TRIM()
Commands: HAVING DATEADD()
DDL DATEDIFF() Logical

Data Grouping: GETDATE() AND | OR | NOT | LIKE


CREATE | ALTER | DROP | CREATE TABLE |
GROUP BY CAST() | BETWEEN | IN | IS |
TRUNCATE | COMMENT | RENAME
COALESCE() EXISTS | ALL | ANY
DQL
Data Sorting: ISNULL()
SELECT ORDER BY NULLIF() Order of Execution
DML LIMIT()
FROM
Data Aggregation: WHERE
INSERT | UPDATE | DELETE
COUNT() Window Functions GROUP BY
DCL
SUM() ROW_NUMBER() HAVING
GRANT | REVOKE AVG() RANK() SELECT

MIN() DENSE_RANK() DISTINCT


DCL
LIMIT/OFFSET
MAX() LAG()
COMMIT | ROLLBACK | SAVEPOINT ORDER BY
Bhushan Mamtani
Simplifying Data Analytics

SQL CHEETSHEET
Bhushan Mamtani
Simplifying Data Analytics

SQL CHEETSHEET
SQL Commands Functions and Clauses
Basic SQL Commands: Aggregate Functions:
SELECT: Retrieves data from database. COUNT(): Counts the number of rows.
FROM: Specifies data source table. SUM(): Calculates the sum of values.
GROUP BY: Groups rows with similar values. AVG(): Calculates the average of values.
WHERE: Filters records based on conditions. MIN(): Retrieves the minimum value.
HAVING: Filters groups based on conditions. MAX(): Retrieves the maximum value.
ORDER BY: Sorts the result set.
Date Functions:
String Functions:
DATE(): Extracts the date part from a datetime value.
CONCAT(): Concatenates two or more strings.
TIME(): Extracts the time part from a datetime value.
SUBSTRING(): Extracts a substring from a string.
YEAR(): Extracts the year from a date or datetime value.
UPPER(): Converts a string to uppercase.
MONTH(): Extracts the month from a date or datetime
LOWER(): Converts a string to lowercase.
value.
LENGTH(): Returns the length of a string.
DAY(): Extracts the day from a date or datetime value.
TRIM(): Removes leading and trailing spaces from a
DATEADD(): Adds a specified number of units to a date or
string.
datetime value.
LEFT(): Returns the leftmost characters of a string.
DATEDIFF(): Calculates the difference between two date
RIGHT(): Returns the rightmost characters of a string.
or datetime values.
GETDATE(): Returns the current date and time.
EXTRACT(): Extracts a part (e.g., year, month, day) from a
date or datetime value.
Bhushan Mamtani
Simplifying Data Analytics

SQL CHEETSHEET
SQL Commands Functions and Clauses
Important definitions
Window Functions
Primary Key: Uniquely identifies each row in a table.
ROW_NUMBER(): Assigns a unique sequential integer
Foreign Key: Links to a primary key in another table.
to each row.
Index: Improves query performance for faster data retrieval.
RANK(): Assigns a unique rank to each row, with gaps
Normalization: Organizes data into structured formats to
in the ranking sequence.
minimize redundancy.
DENSE_RANK(): Assigns a unique rank to each row,
Joins: Combine data from multiple related tables.
without gaps in the ranking sequence.
Aggregate Functions: Perform calculations on grouped data.
NTILE(): Divides the result set into a specified number
Subquery: Nested query within another query for data
of equal-sized groups or buckets.
retrieval.
LEAD(): Accesses data from a subsequent row in the
Transaction: Logical unit of work executed atomically.
same result set.
View: Virtual table based on SELECT query results.
LAG(): Accesses data from a previous row in the same
Constraint: Enforces rules to maintain data integrity.
result set.
Data Definition Language (DDL): Defines database structure.
FIRST_VALUE(): Returns the first value in an ordered
Data Manipulation Language (DML): Manipulates database
set of values.
data.
LAST_VALUE(): Returns the last value in an ordered
Data Control Language (DCL): Manages user access
set of values.
permissions.
Stored Procedure: Precompiled set of SQL statements.
Trigger: Executes automatically on specified database events.

You might also like