SlideShare a Scribd company logo
Standard Query Language
SQL
Lecture 1
Course Expectations
◈ What do you expect from this course?
◈ Prior Exposure to SQL?
◈ My Experience with SQL.
Course Expectations
SQL
• Loading data
• Writing queries
• Knowing the
terminology
Excel
• Becoming
proficient with
formulas and
spreadsheet
structuring
• Learning other
useful features
PowerBI
• Understand what
makes a good
visualization
• Learn how to tell
a story
• Link dashboards
to live data
DMV - All Lectures SQL.pptxpComplete SQL
Database
◈ USER DBMS DATABASE
SQL and Databases
◈ SQL is the language for generating, manipulating, and retrieving data
from a relational database.
◈ Types?
◈ Table, Tuples, Fields, Schema, Primary Key, Foreign Key
◈ Why not Excel?
◈ SQL (Sequel) Vs. MySQL
Relational Databases
SQL Statements
Creating Table and Databases
Data Types
DMV - All Lectures SQL.pptxpComplete SQL
Material to Cover
◈ Databases (Their control and administration)
◈ Select statement
◈ Selection of Database from toolbar or with command
◈ HR Data exploration: How do we start
◈ Entity Relationship Diagram (ERD)
◈ Relationship type: Many, One
◈ Joining Criteria
◈ Importing the HR tables: Countries and Customers
◈ Use of underscore instead of space
One to One: You and your ERP
Many to One: You all studying from me
One to Many: Me teaching you all
Many to Many: Other students studying from
same professor that you have studied from.
Relationship of Customers to Country?
DMV - All Lectures SQL.pptxpComplete SQL
DMV - All Lectures SQL.pptxpComplete SQL
Standard Query Language
SQL
Lecture 3
DMV - All Lectures SQL.pptxpComplete SQL
DMV - All Lectures SQL.pptxpComplete SQL
DMV - All Lectures SQL.pptxpComplete SQL
ERD Diagram
◈ A customer complains about an employee, how to find the data of the
employee?
◈ Why not Country Name as PK and why Country ID?
Star Schema
Snowflake Schema
Topics to Cover in Lecture 2
◈ Text vs Numbers
◈ Comments in SQL: #, --, /*
◈ Not equal to sign
◈ Between command
◈ '[acs]%’ '[!acs]%’
◈ '[a-f]%
Topics to Cover in Lecture 3
◈ Importing Date columns as text
◈ Color coding of SQL: Gray = Operator, Pink = Function
◈ YEAR, MONTH
◈ Temporary Table: INTO #hktemp, INTO ##hktemp
◈ Copying the data to Excel
Topics to Cover in Lecture 4
◈ Refresher of Group By Function
◈ Distinct feature in Excel – Not Done
◈ Flow of Processing SQL commands
◈ ‘Having’ does not depend on Select statement
◈ Distinct feature in Excel
◈ Count Distinct *
Topics to Cover in Lecture 5
◈ ORDER BY 2 or more columns
◈ ORDER BY on String
Inner Join
Left Join
Right Join
Full Outer Join
DMV - All Lectures SQL.pptxpComplete SQL
DMV - All Lectures SQL.pptxpComplete SQL
Null/Not Null
Null/Not Null
◈ Select * from customer where city is NULL;
◈ Is not same as
◈ Select * from customer where city = ‘NULL’;
◈ lets say id <> 2, then it won’t pull up the records with id = null. You have to specifically build that into
condition that id <> 2 and id is null.
SQL Functions
◈ MODULUS or %: Checking the Remainder:
◈ select distinct city from station where ID%2 = 0;
◈ For Even: Either do MOD(ID, 2) = 0 or ID%2 = 0.
◈ For Odd: Either do MOD(ID, 2) = 0 or ID%2 = 1.
◈ POWER(X, 2): To raise x to the power (exponent) of 2.
SQL Functions
SQL Functions
◈ TRIM([characters FROM ]string): removes leading spaces or the characters you specify. LTRIM, RTRIM.
◈ Window Functions:
◈ Over() to open a window: If no column is passed to over(), it is going create one window for all the
records, will iterate over all rows.
◈ Select *, max(salaray) over() as max_salary from employee: this will show max salary among all the
employees.
SQL Functions
◈ ROW_NUMBER() to apply row numbers in a table. Specification in the Over() clause will tell us how to
apply the row number.
◈ Example:
◈ Select a.CITY, a.CITY_LENGTH FROM
◈ (SELECT CITY, LENGTH(CITY) AS CITY_LENGTH,
◈ Row_number() over(order by LENGTH(CITY) asc, city asc) as short_length_rn,
◈ Row_number() over(order by LENGTH(CITY) desc, city asc) as long_length_rn
◈ FROM STATION) as a
◈ where a.short_length_rn = 1 or a.long_length_rn = 1
◈ order by 1 asc;
SQL Functions
◈ DateAdd
◈ Datediff
◈ Left
◈ Right
◈ GetDate

More Related Content

Similar to DMV - All Lectures SQL.pptxpComplete SQL (20)

PDF
Sql1 vol2
Ebtsam Mohamed
 
PPT
Database queries
laiba29012
 
PPT
Toc
Sudharsan S
 
PPT
Toc
Sudharsan S
 
PPTX
Structure Query Language Advance Training
parisaxena1418
 
PPTX
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
PPTX
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
MafnithaKK
 
PPTX
Adbms 21 sql 99 schema definition constraints and queries
Vaibhav Khanna
 
PDF
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Prashant Kumar
 
PPTX
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
PPTX
DB2 Sql Query
Hari Christian
 
PDF
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
PPTX
Crash course in sql
Mithun Shanbhag
 
PDF
SQL.pdf
RiyaSharma335
 
PPT
SQL Queries
Nilt1234
 
PDF
Learning SQL
David Raudales
 
PDF
Learning SQL
DAVID RAUDALES
 
PPTX
SQL.pptx
AmitDas125851
 
PDF
Oracle Material.pdf
rajeshkathavarayan
 
PPTX
SQL Fundamentals
Brian Foote
 
Sql1 vol2
Ebtsam Mohamed
 
Database queries
laiba29012
 
Structure Query Language Advance Training
parisaxena1418
 
SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTER SCIENCE...
MafnithaKK
 
SQL.pptx SAMPLE QUESTION PAPER (THEORY) CLASS: XII SESSION: 2024-25 COMPUTE...
MafnithaKK
 
Adbms 21 sql 99 schema definition constraints and queries
Vaibhav Khanna
 
Sql notes, sql server,sql queries,introduction of SQL, Beginner in SQL
Prashant Kumar
 
DATABASE MANAGMENT SYSTEM (DBMS) AND SQL
Dev Chauhan
 
DB2 Sql Query
Hari Christian
 
sql notes Provideby AGN HUB Tech & It Solutions
mohanagn2244
 
Crash course in sql
Mithun Shanbhag
 
SQL.pdf
RiyaSharma335
 
SQL Queries
Nilt1234
 
Learning SQL
David Raudales
 
Learning SQL
DAVID RAUDALES
 
SQL.pptx
AmitDas125851
 
Oracle Material.pdf
rajeshkathavarayan
 
SQL Fundamentals
Brian Foote
 

Recently uploaded (20)

PDF
Merits and Demerits of DBMS over File System & 3-Tier Architecture in DBMS
MD RIZWAN MOLLA
 
PDF
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
PDF
Product Management in HealthTech (Case Studies from SnappDoctor)
Hamed Shams
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PPTX
apidays Helsinki & North 2025 - API access control strategies beyond JWT bear...
apidays
 
PDF
What does good look like - CRAP Brighton 8 July 2025
Jan Kierzyk
 
PPTX
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
PPTX
SlideEgg_501298-Agentic AI.pptx agentic ai
530BYManoj
 
PDF
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
PDF
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PPTX
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
PDF
Choosing the Right Database for Indexing.pdf
Tamanna
 
PDF
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
PPTX
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
PDF
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
PPT
AI Future trends and opportunities_oct7v1.ppt
SHIKHAKMEHTA
 
PDF
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
PDF
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
PDF
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna
 
Merits and Demerits of DBMS over File System & 3-Tier Architecture in DBMS
MD RIZWAN MOLLA
 
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
Product Management in HealthTech (Case Studies from SnappDoctor)
Hamed Shams
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
apidays Helsinki & North 2025 - API access control strategies beyond JWT bear...
apidays
 
What does good look like - CRAP Brighton 8 July 2025
Jan Kierzyk
 
apidays Munich 2025 - Building an AWS Serverless Application with Terraform, ...
apidays
 
SlideEgg_501298-Agentic AI.pptx agentic ai
530BYManoj
 
R Cookbook - Processing and Manipulating Geological spatial data with R.pdf
OtnielSimopiaref2
 
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
Aict presentation on dpplppp sjdhfh.pptx
vabaso5932
 
Choosing the Right Database for Indexing.pdf
Tamanna
 
apidays Helsinki & North 2025 - Monetizing AI APIs: The New API Economy, Alla...
apidays
 
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
AI Future trends and opportunities_oct7v1.ppt
SHIKHAKMEHTA
 
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna
 
Ad

DMV - All Lectures SQL.pptxpComplete SQL

  • 2. Course Expectations ◈ What do you expect from this course? ◈ Prior Exposure to SQL? ◈ My Experience with SQL.
  • 3. Course Expectations SQL • Loading data • Writing queries • Knowing the terminology Excel • Becoming proficient with formulas and spreadsheet structuring • Learning other useful features PowerBI • Understand what makes a good visualization • Learn how to tell a story • Link dashboards to live data
  • 6. SQL and Databases ◈ SQL is the language for generating, manipulating, and retrieving data from a relational database. ◈ Types?
  • 7. ◈ Table, Tuples, Fields, Schema, Primary Key, Foreign Key ◈ Why not Excel? ◈ SQL (Sequel) Vs. MySQL
  • 10. Creating Table and Databases
  • 13. Material to Cover ◈ Databases (Their control and administration) ◈ Select statement ◈ Selection of Database from toolbar or with command ◈ HR Data exploration: How do we start ◈ Entity Relationship Diagram (ERD) ◈ Relationship type: Many, One ◈ Joining Criteria ◈ Importing the HR tables: Countries and Customers ◈ Use of underscore instead of space
  • 14. One to One: You and your ERP Many to One: You all studying from me One to Many: Me teaching you all Many to Many: Other students studying from same professor that you have studied from. Relationship of Customers to Country?
  • 21. ERD Diagram ◈ A customer complains about an employee, how to find the data of the employee? ◈ Why not Country Name as PK and why Country ID?
  • 24. Topics to Cover in Lecture 2 ◈ Text vs Numbers ◈ Comments in SQL: #, --, /* ◈ Not equal to sign ◈ Between command ◈ '[acs]%’ '[!acs]%’ ◈ '[a-f]%
  • 25. Topics to Cover in Lecture 3 ◈ Importing Date columns as text ◈ Color coding of SQL: Gray = Operator, Pink = Function ◈ YEAR, MONTH ◈ Temporary Table: INTO #hktemp, INTO ##hktemp ◈ Copying the data to Excel
  • 26. Topics to Cover in Lecture 4 ◈ Refresher of Group By Function ◈ Distinct feature in Excel – Not Done ◈ Flow of Processing SQL commands ◈ ‘Having’ does not depend on Select statement ◈ Distinct feature in Excel ◈ Count Distinct *
  • 27. Topics to Cover in Lecture 5 ◈ ORDER BY 2 or more columns ◈ ORDER BY on String
  • 35. Null/Not Null ◈ Select * from customer where city is NULL; ◈ Is not same as ◈ Select * from customer where city = ‘NULL’; ◈ lets say id <> 2, then it won’t pull up the records with id = null. You have to specifically build that into condition that id <> 2 and id is null.
  • 36. SQL Functions ◈ MODULUS or %: Checking the Remainder: ◈ select distinct city from station where ID%2 = 0; ◈ For Even: Either do MOD(ID, 2) = 0 or ID%2 = 0. ◈ For Odd: Either do MOD(ID, 2) = 0 or ID%2 = 1. ◈ POWER(X, 2): To raise x to the power (exponent) of 2.
  • 38. SQL Functions ◈ TRIM([characters FROM ]string): removes leading spaces or the characters you specify. LTRIM, RTRIM. ◈ Window Functions: ◈ Over() to open a window: If no column is passed to over(), it is going create one window for all the records, will iterate over all rows. ◈ Select *, max(salaray) over() as max_salary from employee: this will show max salary among all the employees.
  • 39. SQL Functions ◈ ROW_NUMBER() to apply row numbers in a table. Specification in the Over() clause will tell us how to apply the row number. ◈ Example: ◈ Select a.CITY, a.CITY_LENGTH FROM ◈ (SELECT CITY, LENGTH(CITY) AS CITY_LENGTH, ◈ Row_number() over(order by LENGTH(CITY) asc, city asc) as short_length_rn, ◈ Row_number() over(order by LENGTH(CITY) desc, city asc) as long_length_rn ◈ FROM STATION) as a ◈ where a.short_length_rn = 1 or a.long_length_rn = 1 ◈ order by 1 asc;
  • 40. SQL Functions ◈ DateAdd ◈ Datediff ◈ Left ◈ Right ◈ GetDate