SQL101: Introduction to SQL for Data Analysis
Tags: sql
Published: 2023-02-18 10:44:16

SQL (Structured Query Language) is a programming language designed for managing data in a relational databaseand is the most common method of accessing data in databases . SQL has a variety of functions that allow its users to read, manipulate, and change data. 

Data Cleaning and Exploration: Collect a dataset, clean the data, and perform some exploratory data analysis using Python and SQL. This can help you understand the structure of the data and identify any issues that need to be addressed.

SQL and Python Integration: Create a project that combines SQL and Python to extract data from a database, perform some data analysis in Python, and store the results back in the database.

Building a Web Scraper: Write a script to scrape data from websites and store the data in a database using Python and SQL.

Analyzing Sales Data: Collect sales data from an e-commerce website, and use SQL and Python to perform data analysis and generate insights about customer behavior and sales trends.

Sentiment Analysis: Use Python and SQL to build a sentiment analysis tool that analyzes customer feedback and generates insights into customer sentiment and opinions.

**COMMANDS USED IN SQL**

SQL CREATE DATABASE Command

CREATE DATABASE database_name;
SQL INSERT INTO Command
INSERT INTO table_name( column1, column2....columnN)
VALUES ( value1, value2....valueN);

SQL TRUNCATE TABLE Command

TRUNCATE TABLE table_name;
SQL ALTER TABLE Command
ALTER TABLE table_name {ADD|DROP|MODIFY} column_name {data_ype};
SQL ALTER TABLE Command (Rename)
ALTER TABLE table_name RENAME TO new_table_name;

SQL UPDATE Comman

UPDATE table_name
SET column1 = value1, column2 = value2....columnN=valueN
[ WHERE  CONDITION ];
SQL DELETE Command
DELETE FROM table_name
WHERE  {CONDITION};

SQL DROP DATABASE Command

DROP DATABASE database_name;

SQL DROP TABLE Command

DROP TABLE table_name;
SQL SELECT Command
SELECT column1, column2....columnN
FROM   table_name;
SQL DISTINCT Clause


SELECT DISTINCT column1, column2....columnN
FROM   table_name;

SQL WHERE Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION;
SQL AND/OR Clause

SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION-1 {AND|OR} CONDITION-2;
SQL IN Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name IN (val-1, val-2,...val-N);
SQL BETWEEN Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name BETWEEN val-1 AND val-2;
SQL LIKE Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  column_name LIKE { PATTERN };
SQL ORDER BY Clause
SELECT column1, column2....columnN
FROM   table_name
WHERE  CONDITION
ORDER BY column_name {ASC|DESC};
SQL GROUP BY Clause
SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name;
SQL COUNT Clause
SELECT COUNT(column_name)
FROM   table_name
WHERE  CONDITION;
SQL HAVING Clause
SELECT SUM(column_name)
FROM   table_name
WHERE  CONDITION
GROUP BY column_name
HAVING (arithematic function condition);
SQL CREATE TABLE Command
CREATE TABLE table_name(
column1 datatype,
column2 datatype,
column3 datatype,
.....
columnN datatype,
PRIMARY KEY( one or more columns )
);
SQL CREATE UNIQUE INDEX Command
CREATE UNIQUE INDEX index_name
ON table_name ( column1, column2,...columnN);
SQL DROP INDEX Command
ALTER TABLE table_name
DROP INDEX index_name;
SQL DESC Command
DESC table_name;