0% found this document useful (0 votes)
22 views

Cert - DA - SQL

The document outlines key SQL concepts and commands for storing, manipulating, and retrieving data from databases, including SELECT statements to query data, JOINs to combine data from multiple tables, aggregation functions, grouping and filtering with clauses like WHERE and HAVING. It provides explanations and examples of important SQL elements like SELECT, WHERE, ORDER BY, JOIN, UNION and more to illustrate how SQL is used to work with relational database management systems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Cert - DA - SQL

The document outlines key SQL concepts and commands for storing, manipulating, and retrieving data from databases, including SELECT statements to query data, JOINs to combine data from multiple tables, aggregation functions, grouping and filtering with clauses like WHERE and HAVING. It provides explanations and examples of important SQL elements like SELECT, WHERE, ORDER BY, JOIN, UNION and more to illustrate how SQL is used to work with relational database management systems.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

M. Malik, M.

Ak, CPMA, CIA , CertDA


IHT BPK RI
6 Oktober 2022
TABLE OF CONTENTS

1 THE CRISP-DM FRAMEWORK 5 DATA ANALYTICS METHODOLOGIES

2 BIG DATA AND DATA ANALYTICS 6 MAINSTREAM TOOLS AND KEY APPLICATIONS

3 SOURCES OF DATA 7 DATA VISUALIZATION AND


COMMUNICATION

4 TYPES OF ANALYTICS 8 SKEPTICISM AND ETHICAL CONSIDERATIONS


SQL is a standard language for storing, manipulating and retrieving
data in databases.

What is SQL?
 SQL stands for Structured Query Language
 SQL lets you access and manipulate databases
 SQL became a standard of the American National Standards Institute (ANSI) in
1986, and of the International Organization for Standardization (ISO) in 1987

What Can SQL do? What Can SQL do?


 SQL can execute queries against a  SQL can create new databases
database  SQL can create new tables in a database
 SQL can retrieve data from a database  SQL can create stored procedures in a
 SQL can insert records in a database database
 SQL can update records in a database  SQL can create views in a database
 SQL can delete records from a database  SQL can set permissions on tables,
procedures, and views
Although SQL is an ANSI/ISO standard, there are different versions of the SQL language.
However, to be compliant with the ANSI standard, they all support at least the major commands (such as SELECT, UPDATE, DELETE, INSERT, WHERE) in a similar
manner
SQL Syntax
The Most Important SQL Commands
 SELECT - extracts data from a database
 UPDATE - updates data in a database
 DELETE - deletes data from a database
 INSERT INTO - inserts new data into a database
 CREATE DATABASE - creates a new database
 ALTER DATABASE - modifies a database
 CREATE TABLE - creates a new table
 ALTER TABLE - modifies a table
 DROP TABLE - deletes a table
 CREATE INDEX - creates an index (search key)
 DROP INDEX - deletes an index
The SQL SELECT Statement
The SELECT statement is used to select data from a database.
The data returned is stored in a result table, called the result-set.

SELECT column1, column2 FROM table_name;

SELECT * FROM [Customers] ;


SELECT CustomerName,Address,… FROM [Customers];

The SQL SELECT DISTINCT Statement


The SELECT DISTINCT statement is used to return only distinct (different) values.
Inside a table, a column often contains many duplicate values; and sometimes you only want to list the
different (distinct) values.

SELECT DISTINCT column1, column2,… FROM table_name;


SELECT DISTINCT Country FROM Customers;
SELECT COUNT(DISTINCT Country) FROM Customers;
The SQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.

SELECT column1, column2, ...


FROM table_name
WHERE condition;

The WHERE clause is not only used in SELECT statements, it is also used in UPDATE, DELETE, etc.!

SELECT * FROM Customers


WHERE Country='Mexico';

SELECT * FROM Customers


WHERE CustomerID=1;
The SQL AND, OR and NOT Operators
The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition:
 The AND operator displays a record if all the conditions separated by AND are TRUE.
 The OR operator displays a record if any of the conditions separated by OR is TRUE.
 The NOT operator displays a record if the condition(s) is NOT TRUE.

SELECT * FROM Customers


WHERE City='Berlin' OR City='München';

SELECT * FROM Customers


WHERE NOT Country='Germany';

SELECT * FROM Customers


WHERE Country='Germany' AND (City='Berlin' OR City='München');

SELECT * FROM Customers


WHERE NOT Country='Germany' AND NOT Country='USA';
The SQL ORDER BY Keyword
The ORDER BY keyword is used to sort the result-set in ascending or descending
order.

The ORDER BY keyword sorts the records in ascending order by default. To sort the
records in descending order, use the DESC keyword.

SELECT column1, column2, ...


FROM table_name
ORDER BY column1, column2, ... ASC|DESC;

SELECT * FROM Customers


ORDER BY Country DESC;

SELECT * FROM Customers


ORDER BY Country, CustomerName;

SELECT * FROM Customers


ORDER BY Country ASC, CustomerName DESC;
The SQL MIN() and MAX() Functions
The MIN() function returns the smallest value of the selected column.
The MAX() function returns the largest value of the selected column.

SELECT MIN(column_name) SELECT MIN(Price) AS SmallestPrice


FROM table_name FROM Products;
WHERE condition;

SELECT MAX(column_name)
SELECT MAX(Price) AS LargestPrice
FROM table_name
FROM Products;
WHERE condition;
The SQL COUNT(), AVG() and SUM() Functions
The COUNT() function returns the number of rows that matches a specified criterion.

SELECT COUNT(column_name)
SELECT COUNT(ProductID)
FROM table_name
FROM Products;
WHERE condition;

SELECT SUM(column_name)
FROM table_name SELECT SUM(Quantity)
WHERE condition; FROM OrderDetails;

SELECT AVG(column_name) SELECT AVG(Price)


FROM table_name FROM Products;
WHERE condition;
The SQL GROUP BY Statement
The GROUP BY statement groups rows that have the same values into
summary rows, like "find the number of customers in each country".
The GROUP BY statement is often used with aggregate functions
(COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one
or more columns.

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country;

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;
The SQL HAVING Clause
The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate
functions.

SELECT COUNT(CustomerID), Country


FROM Customers
GROUP BY Country
SELECT column_name(s)
HAVING COUNT(CustomerID) > 5;
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5
ORDER BY COUNT(CustomerID) DESC;
The SQL LIKE Operator
The LIKE operator is used in a WHERE clause to search for a specified
pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator:
• The percent sign (%) represents zero, one, or multiple characters
• The underscore sign (_) represents one, single character

SELECT column1, column2, ...


FROM table_name
WHERE columnN LIKE pattern;

SELECT * FROM Customers


WHERE CustomerName LIKE '%a';

SELECT * FROM Customers


WHERE CustomerName LIKE '_r%';

SELECT * FROM Customers


WHERE City LIKE '[bsp]%';
The SQL IN Operator
The IN operator allows you to specify multiple values in a WHERE clause.
The IN operator is a shorthand for multiple OR conditions.

SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);

SELECT * FROM Customers


WHERE Country IN ('Germany', 'France', 'UK');

SELECT * FROM Customers


WHERE Country IN (SELECT Country FROM Suppliers);
SQL JOIN
A JOIN clause is used to combine rows from two or more tables, based on a
related column between them.

Different Types of SQL JOINs


Here are the different types of the JOINs in SQL:
 (INNER) JOIN: Returns records that have matching values in both tables
 LEFT (OUTER) JOIN: Returns all records from the left table, and the matched records
from the right table
 RIGHT (OUTER) JOIN: Returns all records from the right table, and the matched
records from the left table
 FULL (OUTER) JOIN: Returns all records when there is a match in either left or right
table
The SQL UNION Operator
The UNION operator is used to combine the result-set of two or
more SELECT statements.
•Every SELECT statement within UNION must have the same number of columns
•The columns must also have similar data types
•The columns in every SELECT statement must also be in the same order

SELECT City FROM Customers


SELECT column_name(s) FROM table1
UNION
UNION
SELECT City FROM Suppliers
SELECT column_name(s) FROM table2;
ORDER BY City;

SELECT Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders


FROM Orders
INNER JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
WHERE LastName = 'Davolio' OR LastName = 'Fuller'
GROUP BY LastName
HAVING COUNT(Orders.OrderID) > 25;
The SQL INSERT INTO Statement
The INSERT INTO statement is used to insert new records in a table.

INSERT INTO table_name (column1, column2, column3, ...)


VALUES (value1, value2, value3, ...);

INSERT INTO table_name


VALUES (value1, value2, value3, ...);

INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)


VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');

INSERT INTO Customers (CustomerName, City, Country)


VALUES ('Cardinal', 'Stavanger', 'Norway');
The SQL UPDATE Statement
The UPDATE statement is used to modify the existing records in a table.

UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;

UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;

Be careful when updating records. If you omit the WHERE clause, ALL records will
be updated!
The SQL DELETE Statement
The DELETE statement is used to delete existing records in a table.

DELETE FROM table_name WHERE condition;

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';


The SQL CREATE DATABASE Statement
The CREATE DATABASE statement is used to create a new SQL database.

The SQL DROP DATABASE Statement


The DROP DATABASE statement is used to drop an existing SQL database.

The SQL BACKUP DATABASE Statement


The BACKUP DATABASE statement is used in SQL Server to create a full back up of an existing SQL database.

The SQL CREATE TABLE Statement


The CREATE TABLE statement is used to create a new table in a database

The SQL DROP TABLE Statement


The DROP TABLE statement is used to drop an existing table in a database.

SQL ALTER TABLE Statement


The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing table.
This slide presentation refers to:

https://www.w3schools.com/sql/default.asp

You might also like