DMV - All Lectures SQL.pptxpComplete SQL

ssuser68b4231 9 views 40 slides Jun 07, 2024
Slide 1
Slide 1 of 40
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40

About This Presentation

this has whole SQL lectures


Slide Content

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

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 Dropping Table and Databases

Data Types

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?

Standard Query Language SQL Lecture 3

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

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
Tags