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

MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

PILOT - CLASS
RAMADHAN KHANSA AKBARI

Basic sql
FOR ANALYSIS
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

TABLE OF CONTENT
Literal, operator,
01 SQL Introduction 02 function, filtering

DATA sorting, AGgREGATION,


03 data grouping 04 Combining data
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SQL
01
Introduction
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

What is sql?
SQL or Structured Query Language is a simple computer
language used for communicating with Relational Database
System.
SQL have some category :

● Data Definition Language (DDL)


use to take and change database structure object

● Data Manipulation Language (DML)


use to take and change the content of the table

On this class, we only focus on using DML, specially SELECT.


MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

‘Select’ statement
SELECT is one of SQL QUERY used for retrieving data
from one or some RDBMS table

SELECT syntax :

SELECT column_name1, column_name2,… FROM table_name


MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

EXample

Using SELECT statement to


retrieve two columns data
(nama_produk and harga) from
ms_produk_dqlab table
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

EXample

Using SELECT statement to


retrieve all columns data
With * from
ms_produk_dqlab table
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

prefix
PREFIX is part of database object’s name with higher
hierarchy
PREFIX can be written :

PREFIX database_object’s_name
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

alias
ALIAS is used to guve a table, or a column in a table, a
temporary name.
ALIAS can be written :

Database_object’s_name as [ALIAS]

Database_object’s_name [ALIAS]
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

EXample

Both picture above is the example use


of ALIAS with ‘as’ and no.
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Literal, Operator,
02 Function, filtering
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

literal
LITERALS are the string or integer values representing
data retrieved from the database.
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Mathematical OPERATOR comparison operator


MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

function
FUNCTION is a stored program that you can pass parameters into and
then return a value. Here are some function we could use in MySQL
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

filtering
Filtering is a is a process for limit the output data generated based on
the condition or some criteria. The application of filtering in MySQL is
using WHERE

SELECT … FROM table_name WHERE [comparison


expression]
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Sample case
Can you help the sales team to show all
transactions with their price and quantity so
that they know which product has the highest
sale with minimum purchase 200,000 ?
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SOLUTION
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Sample case
A customer name Agus Cahyono complains to
customer service regarding warranty issues. Help CS
to find out if the customer can still claim the warranty
(Company’s warranty rules :
1. Two and a half year maximum / 732 days
2. Only applicable on electronic purchase)
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SOLUTION
Customer List
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

It appears that Mr. Agus Cahyono with customer code


dqlabcust07 can’t claim the warranty because the
TRX_DAYS exceed the company’s warrant policy
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Data sorting
03 aggregation
Data grouping
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Data sorting
Data sorting in MySQL can be done with ORDER BY keyword.
ORDER BY used to sort the result-set in ascending or descending
order. The ORDER BY sorts the record in ascending order by default

ORDER BY on SELECT statement syntax :

SELECT … FROM table_name ORDER BY field_name

SELECT … FROM table_name ORDER BY field_name ASC

SELECT … FROM table_name ORDER BY field_name DESC


MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

aggregation
MySQL's aggregate function is used to perform calculations on multiple values
and return the result in a single value like the average of all values, the sum of all
values, and maximum & minimum value among certain groups of values

SELECT function(field) FROM table_name


MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

aggregation
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Data grouping
The MYSQL GROUP BY clause is used to collect data from multiple records
and group the result by one or more column. It is generally used in a SELECT
statement.

SELECT field1,field2, agg_function FROM table_name


GROUP BY field1, field2
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

having
The HAVING clause was added to SQL because the WHERE keyword
cannot be used with aggregate functions.

SELECT … FROM table_name


GROUP BY … HAVING [comparison expression]
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Sample case
Help the marketing team to know which of the
product is the best seller and which product sold less
by displaying all the total sales of the product with
condition the product sold more than 3.
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SOLUTION

It can be seen from the list


that the best seller is STICKY NOTES and FLASHDISK
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Sample case
Help Marketing Team to find the candidate for the
giveaway winner who buy most of the product.
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SOLUTION

It can be seen from the list


that the customer with ‘dqlabcust02’ has the biggest purchase
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SOLUTION

From this list, we can inform that the winner of the giveaway contest
is Heidi Goh
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

04 Combining data
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

join
JOINS in MySQL are used to retrieve data from multiple tables. A
MySQL JOINS are performed whenever two or more tables are joined in
SQL statement.

SELECT … FROM table_name1


JOIN table_name2 ON [filtering expression]

JOINS statement without filtering expression are often called CROSS


JOIN
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

EXample

JOIN statement with filtering expression


MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

EXample

JOIN statement without filtering


expression
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Join in mysql
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Sample case
Help Packer order team to find the name, addresses
and the item they purchased from the shop (Only for
member)
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

SOLUTION
MENU ANALYSIS CONTACT DQLab Pilot class – Data analyst

Thank
you

You might also like