SQL is a software that manages data. It uses data queries.
SQL is capable of doing simple data statistics. For example, central tenendies which are mid points. Mean, mode varance of the data which describes how spread out the data is and ranges. How data is distributes. When we have a bell cure we can measure standard diviation which is how wide the bell curve is.
There are two things that we can do with statistics. Hypothesis testing, examples does customers in southestern states make more purchases than cutomers in the northwestern states. e.i. whether cusotmers over the ae of 40 spend more per year than customers under the age of 30. would cusotmers click on an add that has an image than only text. X’s: Customers ID, costumers name, costumers address, costumers city, customers state, customers age, number of purchase this year, total amount of purchses.
SELECT "month_idx", "year", "month", SUM(CASE WHEN ("term_deposit" = 'yes') THEN (1.0) ELSE (0.0) END) AS "subscribe",
COUNT(*) AS "total"
FROM ("bank")
GROUP BY "month_idx", "year", "month"
SELECT * FROM customer_summary
WHERE age > 40
finding the mean of number of purchases and meand of amount of purchases.
SELECT AVG(number_purchase), AVG(amount_purchase)
FROM customer_summary WHERE age > 40.
You have:
MAX, MIN MODE, STDDEV
Missing values
SELECT * FROM store_sales
WHERE units_sold IS NULL
Out of Range Values
SELECT * FROM employees
WHERE (age < 0) AND (age >120)
Example: Knowing there are 10 people max working at a location.
SELECT * FROM store_sales
WHERE employee_shift > 10
Lower bown check
SELECT * FROM store_sales
WHERE employee_shifts > 10 OR
employee_shifts < 0
Minimum Function
SELECT MIN(age) FROM employee
SELECT
MIN(age)
MIN(start_date),
MIN(num_vacation_days)
FROM employees
Finding the maximum value of an attribute from column age data employees
SELECT MAX(age) FROM employees
Example II
SELECT
MAX(age)
MAX(start_date),
MAX(num_vacation_days)
FROM employees
Ordering and Counting
SELECT age FROM employees
ORDER BY age
Prderring Descending
SELECT age FROM employees
ORDER BY age DESC
Multi-Column Order
SELECT age, start_date
FROM employees
ORDER BY age, start_date
Counting
SELECT COUNT(age)
FROM employees
Mltiple Counting
SELECT
COUNT(age),
COUNT(start_date)
FROM employees
Mix Aggregates
SELECT COUNT(age),
COUNT(staet_date),
MAX(age), MAX(start_date),
MIN(age), MIN(start_date)
FROM employees
Repeat Function. Repeats * ten times.
REPEAT('*', 10)
Correlation
SELECT
CORR(units_sold, total_revenue) FROM Product_sales
SQL is use to get csv files or excel files and get data from them put them in a new csv file. It Manipulate the current csv files and create reports.
Most common use 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
e.g. SELECT column1, column2, … #this would show only colum one and 2 FROM table_name;
e.g. SELECT * FROM table_name; # this would show the whole table.
Popular Links