0% found this document useful (0 votes)
5 views5 pages

SQL Examples

The document outlines essential practices for data analysts, emphasizing careful data reading and visualization. It includes important MySQL Workbench rules and provides various SQL query examples for analyzing shipments and sales data. Key queries demonstrate how to filter data by sales person, date ranges, and specific product characteristics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

SQL Examples

The document outlines essential practices for data analysts, emphasizing careful data reading and visualization. It includes important MySQL Workbench rules and provides various SQL query examples for analyzing shipments and sales data. Key queries demonstrate how to filter data by sales person, date ranges, and specific product characteristics.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MAIN AIM OF DATA ANALYST : Must Read the data very carefully ,majority oof time always Read

and

Visualization

MySQL Workbench Rules (IMPORTANT)

• Strings → 'SP02'

• Never use empty→ “ ” or ‘ ’

• Column names with spaces → `Sales Person`

• EXTRACT(YEAR_MONTH ...) (not recommended in MySQL)

• Use YEAR() and MONTH() or date ranges

READ THE DATA - SELECT * FROM [Link];

Now read the shipments data : SELECT * FROM [Link];


# SQL Examples

# 1 – See all shipments

SELECT Product, [Link], Amount, Boxes FROM shipments s;

# 2 – All shipments by SP02

select * from shipments s

where s.`Sales Person` = 'SP02';

# 3 – All shipments by SP02 to G3

select * from shipments s

where s.`Sales Person` = 'SP02' and [Link] = 'G3'


order by [Link] desc;

4 – All shipments in Jan 2023

SELECT *FROM ac_telugu.shipments_new s

WHERE [Link] >= '2023-01-01'

AND [Link] < '2023-02-01';

Using MONTH / YEAR

SELECT *

FROM shipments_new s

WHERE YEAR([Link]) = 2023

AND MONTH([Link]) = 1;

5 – All shipments by SP02, SP03, SP12, SP15

SELECT *FROM shipments_new s

WHERE s.`Sales Person` IN ('SP02', 'SP03', 'SP12', 'SP15');

6 – Products that contain choco

SELECT *

FROM products

WHERE product LIKE '%choco%';

7 – Sales persons whose name begins with S

SELECT *FROM people

WHERE `Sales Person` LIKE 'S%';

8 – Sales per box in Feb 2023

SELECT

[Link],

[Link],

[Link],

ROUND([Link] / [Link], 1) AS `Amount per Box`


FROM shipments_new s

WHERE [Link] >= '2023-02-01'

AND [Link] < '2023-03-01';

9 – All shipment data for Subbarao

Check person record

SELECT *FROM people

WHERE `Sales Person` LIKE 'Subba%';

Using JOIN (correct approach)

SELECT

p.`Sales Person`,

[Link],

[Link],

[Link]

FROM shipments_new s

JOIN people p

ON p.`SP ID` = s.`Sales Person`

WHERE p.`Sales Person` LIKE 'Subba%';

10 – Subbarao shipment data by month

SELECT

YEAR([Link]) AS year,

MONTH([Link]) AS month,

SUM([Link]) AS total_amount,

SUM([Link]) AS total_boxes

FROM shipments_new s

JOIN people p

ON p.`SP ID` = s.`Sales Person`

WHERE p.`Sales Person` LIKE 'Subba%'

GROUP BY YEAR([Link]), MONTH([Link])

ORDER BY year, month;

You might also like