SlideShare a Scribd company logo

Advanced SQL Webinar

Ram Kedem
Ram Kedem

December 2016

1 of 34
Advanced SQL - Tips & Tricks
Ram kedem
About Me
• Data Team Leader at PLYmedia
• During the last decade trained thousands of people (Israel and
abroad) various topic related to the database world.
• Managing an educational website mainly focused on the SQL
language
• Owner of Ram Kedem Training
About this Book
• Gathered over a period of almost 10 years
• Includes 265 pages and 100 Different
complex SQL use-cases
• First of its kind in Israel
• Aims to provide practical knowledge based
on real user experience
• Available in Hard-Copy & Online version
Goals
• Learn real use cases of :
• Advanced Scalar Functions
• Analytic Functions
• Group Functions
• Complex Sub-Queries
• CTE and Recursive CTE
• SET Operators
• XML tricks
‫שונים‬ ‫פורומים‬ ‫המנהל‬ ‫אינטרנט‬ ‫לאתר‬,‫שונים‬ ‫משתמשים‬ ‫של‬ ‫ההודעות‬ ‫תוכן‬ ‫את‬ ‫המכילה‬ ‫טבלה‬ ‫קיימת‬.
‫אפליקצייה‬ ‫שגיאות‬ ‫בשל‬ ‫לעיתים‬,‫סימני‬ ‫נכנסים‬ ‫המלל‬ ‫בתוך‬%
‫שונות‬ ‫טכניקות‬ ‫שתי‬ ‫באמצעות‬,‫אחוז‬ ‫מכילים‬ ‫אשר‬ ‫הערכים‬ ‫את‬ ‫מצאו‬)%(
1.‫אחוז‬ ‫עם‬ ‫ערכים‬ ‫מציאת‬
1.‫אחוז‬ ‫עם‬ ‫ערכים‬ ‫מציאת‬
• escape_character
• Is a character that is put in front of a wildcard character to indicate
that the wildcard should be interpreted as a regular character and
not as a wildcard.
• escape_character is a character expression that has no default and
must evaluate to only one character
SELECT *
FROM percent_values
WHERE id LIKE '%^%%' ESCAPE '^'

Recommended

Advanced Sql Training
Advanced Sql TrainingAdvanced Sql Training
Advanced Sql Trainingbixxman
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands1keydata
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functionsfarwa waqar
 
Chapter 07 ddl_sql
Chapter 07 ddl_sqlChapter 07 ddl_sql
Chapter 07 ddl_sqlNazir Ahmed
 

More Related Content

What's hot (20)

Sql basics
Sql  basicsSql  basics
Sql basics
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
SQL - Structured query language introduction
SQL - Structured query language introductionSQL - Structured query language introduction
SQL - Structured query language introduction
 
Mysql
MysqlMysql
Mysql
 
BIS05 Introduction to SQL
BIS05 Introduction to SQLBIS05 Introduction to SQL
BIS05 Introduction to SQL
 
A must Sql notes for beginners
A must Sql notes for beginnersA must Sql notes for beginners
A must Sql notes for beginners
 
Sql operator
Sql operatorSql operator
Sql operator
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
SQL commands
SQL commandsSQL commands
SQL commands
 
Chapter8 my sql revision tour
Chapter8 my sql revision tourChapter8 my sql revision tour
Chapter8 my sql revision tour
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
SQL
SQLSQL
SQL
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
Assignment#07
Assignment#07Assignment#07
Assignment#07
 
SQL Server Learning Drive
SQL Server Learning Drive SQL Server Learning Drive
SQL Server Learning Drive
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
Sql
SqlSql
Sql
 

Viewers also liked

Managing oracle Database Instance
Managing oracle Database InstanceManaging oracle Database Instance
Managing oracle Database InstanceRam Kedem
 
SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?Zohar Elkayam
 
MSSQL Server - Automation
MSSQL Server - AutomationMSSQL Server - Automation
MSSQL Server - AutomationRam Kedem
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsOOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsZohar Elkayam
 
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)Beat Signer
 
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...Beat Signer
 
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Beat Signer
 
eStudio 34 InAppEvent - Billy Mobile User Acquisition and Monetization
eStudio 34 InAppEvent - Billy Mobile User Acquisition and MonetizationeStudio 34 InAppEvent - Billy Mobile User Acquisition and Monetization
eStudio 34 InAppEvent - Billy Mobile User Acquisition and MonetizationWilliam Renedo
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Beat Signer
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Beat Signer
 
DATA WAREHOUSING
DATA WAREHOUSINGDATA WAREHOUSING
DATA WAREHOUSINGKing Julian
 

Viewers also liked (13)

Managing oracle Database Instance
Managing oracle Database InstanceManaging oracle Database Instance
Managing oracle Database Instance
 
SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?SQLcl the next generation of SQLPlus?
SQLcl the next generation of SQLPlus?
 
MSSQL Server - Automation
MSSQL Server - AutomationMSSQL Server - Automation
MSSQL Server - Automation
 
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic FunctionsOOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
OOW2016: Exploring Advanced SQL Techniques Using Analytic Functions
 
Exploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic FunctionsExploring Advanced SQL Techniques Using Analytic Functions
Exploring Advanced SQL Techniques Using Analytic Functions
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
Advanced SQL - Lecture 6 - Introduction to Databases (1007156ANR)
 
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
Extended ER Model and other Modelling Languages - Lecture 2 - Introduction to...
 
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
Relational Model and Relational Algebra - Lecture 3 - Introduction to Databas...
 
eStudio 34 InAppEvent - Billy Mobile User Acquisition and Monetization
eStudio 34 InAppEvent - Billy Mobile User Acquisition and MonetizationeStudio 34 InAppEvent - Billy Mobile User Acquisition and Monetization
eStudio 34 InAppEvent - Billy Mobile User Acquisition and Monetization
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
 
DATA WAREHOUSING
DATA WAREHOUSINGDATA WAREHOUSING
DATA WAREHOUSING
 

Similar to Advanced SQL Webinar

Similar to Advanced SQL Webinar (20)

Sql Patterns
Sql PatternsSql Patterns
Sql Patterns
 
Obtain better data accuracy using reference tables
Obtain better data accuracy using reference tablesObtain better data accuracy using reference tables
Obtain better data accuracy using reference tables
 
Sql 2006
Sql 2006Sql 2006
Sql 2006
 
Db1 lecture4
Db1 lecture4Db1 lecture4
Db1 lecture4
 
Introduction to sq lite
Introduction to sq liteIntroduction to sq lite
Introduction to sq lite
 
Chapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdfChapter – 6 SQL Lab Tutorial.pdf
Chapter – 6 SQL Lab Tutorial.pdf
 
Spufi
SpufiSpufi
Spufi
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
lecture2.ppt
lecture2.pptlecture2.ppt
lecture2.ppt
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
R_CheatSheet.pdf
R_CheatSheet.pdfR_CheatSheet.pdf
R_CheatSheet.pdf
 
Lecture5-SQL.docx
Lecture5-SQL.docxLecture5-SQL.docx
Lecture5-SQL.docx
 
ADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASADADVANCE ITT BY PRASAD
ADVANCE ITT BY PRASAD
 
Sql basics
Sql basicsSql basics
Sql basics
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Sql General
Sql General Sql General
Sql General
 
SQL
SQLSQL
SQL
 
Oracle sql tutorial
Oracle sql tutorialOracle sql tutorial
Oracle sql tutorial
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 

More from Ram Kedem

Impala use case @ edge
Impala use case @ edgeImpala use case @ edge
Impala use case @ edgeRam Kedem
 
Power Pivot and Power View
Power Pivot and Power ViewPower Pivot and Power View
Power Pivot and Power ViewRam Kedem
 
Data Mining in SSAS
Data Mining in SSASData Mining in SSAS
Data Mining in SSASRam Kedem
 
Data mining In SSAS
Data mining In SSASData mining In SSAS
Data mining In SSASRam Kedem
 
SQL Injections - Oracle
SQL Injections - OracleSQL Injections - Oracle
SQL Injections - OracleRam Kedem
 
SSAS Attributes
SSAS AttributesSSAS Attributes
SSAS AttributesRam Kedem
 
DDL Practice (Hebrew)
DDL Practice (Hebrew)DDL Practice (Hebrew)
DDL Practice (Hebrew)Ram Kedem
 
DML Practice (Hebrew)
DML Practice (Hebrew)DML Practice (Hebrew)
DML Practice (Hebrew)Ram Kedem
 
Exploring Oracle Database Architecture (Hebrew)
Exploring Oracle Database Architecture (Hebrew)Exploring Oracle Database Architecture (Hebrew)
Exploring Oracle Database Architecture (Hebrew)Ram Kedem
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQLRam Kedem
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to DatabasesRam Kedem
 
Deploy SSRS Project - SQL Server 2014
Deploy SSRS Project - SQL Server 2014Deploy SSRS Project - SQL Server 2014
Deploy SSRS Project - SQL Server 2014Ram Kedem
 
Pig - Processing XML data
Pig - Processing XML dataPig - Processing XML data
Pig - Processing XML dataRam Kedem
 
SSAS Cubes & Hierarchies
SSAS Cubes & HierarchiesSSAS Cubes & Hierarchies
SSAS Cubes & HierarchiesRam Kedem
 
SSRS Basic Parameters
SSRS Basic ParametersSSRS Basic Parameters
SSRS Basic ParametersRam Kedem
 
SSRS Conditional Formatting
SSRS Conditional FormattingSSRS Conditional Formatting
SSRS Conditional FormattingRam Kedem
 
SSRS Calculated Fields
SSRS Calculated FieldsSSRS Calculated Fields
SSRS Calculated FieldsRam Kedem
 

More from Ram Kedem (20)

Impala use case @ edge
Impala use case @ edgeImpala use case @ edge
Impala use case @ edge
 
Power Pivot and Power View
Power Pivot and Power ViewPower Pivot and Power View
Power Pivot and Power View
 
Data Mining in SSAS
Data Mining in SSASData Mining in SSAS
Data Mining in SSAS
 
Data mining In SSAS
Data mining In SSASData mining In SSAS
Data mining In SSAS
 
SQL Injections - Oracle
SQL Injections - OracleSQL Injections - Oracle
SQL Injections - Oracle
 
SSAS Attributes
SSAS AttributesSSAS Attributes
SSAS Attributes
 
SSRS Matrix
SSRS MatrixSSRS Matrix
SSRS Matrix
 
DDL Practice (Hebrew)
DDL Practice (Hebrew)DDL Practice (Hebrew)
DDL Practice (Hebrew)
 
DML Practice (Hebrew)
DML Practice (Hebrew)DML Practice (Hebrew)
DML Practice (Hebrew)
 
Exploring Oracle Database Architecture (Hebrew)
Exploring Oracle Database Architecture (Hebrew)Exploring Oracle Database Architecture (Hebrew)
Exploring Oracle Database Architecture (Hebrew)
 
Introduction to SQL
Introduction to SQLIntroduction to SQL
Introduction to SQL
 
Introduction to Databases
Introduction to DatabasesIntroduction to Databases
Introduction to Databases
 
Deploy SSRS Project - SQL Server 2014
Deploy SSRS Project - SQL Server 2014Deploy SSRS Project - SQL Server 2014
Deploy SSRS Project - SQL Server 2014
 
Pig - Processing XML data
Pig - Processing XML dataPig - Processing XML data
Pig - Processing XML data
 
SSAS Cubes & Hierarchies
SSAS Cubes & HierarchiesSSAS Cubes & Hierarchies
SSAS Cubes & Hierarchies
 
SSRS Basic Parameters
SSRS Basic ParametersSSRS Basic Parameters
SSRS Basic Parameters
 
SSRS Gauges
SSRS GaugesSSRS Gauges
SSRS Gauges
 
SSRS Conditional Formatting
SSRS Conditional FormattingSSRS Conditional Formatting
SSRS Conditional Formatting
 
SSRS Calculated Fields
SSRS Calculated FieldsSSRS Calculated Fields
SSRS Calculated Fields
 
SSRS Groups
SSRS GroupsSSRS Groups
SSRS Groups
 

Recently uploaded

spring_bee_bot_creations_erd primary.pdf
spring_bee_bot_creations_erd primary.pdfspring_bee_bot_creations_erd primary.pdf
spring_bee_bot_creations_erd primary.pdfKonstantina Koutsodimou
 
2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptx2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptxMaryPotorti1
 
Digital Footprints to Career Pathways - Building a Strong Professional Online...
Digital Footprints to Career Pathways - Building a Strong Professional Online...Digital Footprints to Career Pathways - Building a Strong Professional Online...
Digital Footprints to Career Pathways - Building a Strong Professional Online...Sue Beckingham
 
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaDecision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaPrince Armah, PhD
 
A TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTS
A TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTSA TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTS
A TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTSDr.M.Geethavani
 
CATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docxCATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docxAizaPolinarCruz
 
11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf
11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf
11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdfAynouraHamidova
 
Add Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesAdd Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesCeline George
 
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...AKSHAYMAGAR17
 
Plagiarism, Types & Consequences by Dr. Sarita Anand
Plagiarism, Types & Consequences by Dr. Sarita AnandPlagiarism, Types & Consequences by Dr. Sarita Anand
Plagiarism, Types & Consequences by Dr. Sarita AnandDr. Sarita Anand
 
Nzinga Kika - The story of the queen
Nzinga Kika    -  The story of the queenNzinga Kika    -  The story of the queen
Nzinga Kika - The story of the queenDeanAmory1
 
Kartik Nair In Media Res Media Component
Kartik Nair In Media Res Media ComponentKartik Nair In Media Res Media Component
Kartik Nair In Media Res Media ComponentInMediaRes1
 
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...SUMIT TIWARI
 
Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...
Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...
Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...i3 Health
 
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary  Education in LithuaniaAndreas Schleicher_ Strengthening Upper Secondary  Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary Education in LithuaniaEduSkills OECD
 
Mycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with MorganMycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with MorganMargie Morgan
 
Organic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional GroupsOrganic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional GroupsDr.M.Geethavani
 
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Katherine Villaluna
 
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdfDr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdfDr.Florence Dayana
 
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...AKSHAYMAGAR17
 

Recently uploaded (20)

spring_bee_bot_creations_erd primary.pdf
spring_bee_bot_creations_erd primary.pdfspring_bee_bot_creations_erd primary.pdf
spring_bee_bot_creations_erd primary.pdf
 
2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptx2.27.24 Malcolm X and the Black Freedom Struggle.pptx
2.27.24 Malcolm X and the Black Freedom Struggle.pptx
 
Digital Footprints to Career Pathways - Building a Strong Professional Online...
Digital Footprints to Career Pathways - Building a Strong Professional Online...Digital Footprints to Career Pathways - Building a Strong Professional Online...
Digital Footprints to Career Pathways - Building a Strong Professional Online...
 
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in GhanaDecision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
Decision on Curriculum Change Path: Towards Standards-Based Curriculum in Ghana
 
A TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTS
A TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTSA TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTS
A TEXTBOOK OF INTELLECTUAL ROPERTY RIGHTS
 
CATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docxCATCH UP FRIDAY LESSON PLAN GRADE 6.docx
CATCH UP FRIDAY LESSON PLAN GRADE 6.docx
 
11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf
11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf
11 CI SINIF SINAQLARI - 10-2023-Aynura-Hamidova.pdf
 
Add Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 SalesAdd Products From Catalog in Odoo 17 Sales
Add Products From Catalog in Odoo 17 Sales
 
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
Genetics, Heredity, Variation, history, its roles, Scope, Importance, and Bra...
 
Plagiarism, Types & Consequences by Dr. Sarita Anand
Plagiarism, Types & Consequences by Dr. Sarita AnandPlagiarism, Types & Consequences by Dr. Sarita Anand
Plagiarism, Types & Consequences by Dr. Sarita Anand
 
Nzinga Kika - The story of the queen
Nzinga Kika    -  The story of the queenNzinga Kika    -  The story of the queen
Nzinga Kika - The story of the queen
 
Kartik Nair In Media Res Media Component
Kartik Nair In Media Res Media ComponentKartik Nair In Media Res Media Component
Kartik Nair In Media Res Media Component
 
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
Bilingual notes of Pharmacognosy chapter 4Glycosides, Volatile oils,Tannins,R...
 
Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...
Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...
Enhancing MRD Testing in Hematologic Malignancies: When Negativity is a Posit...
 
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary  Education in LithuaniaAndreas Schleicher_ Strengthening Upper Secondary  Education in Lithuania
Andreas Schleicher_ Strengthening Upper Secondary Education in Lithuania
 
Mycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with MorganMycology Update February 2024 Microbes with Morgan
Mycology Update February 2024 Microbes with Morgan
 
Organic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional GroupsOrganic Synthesis and Estimation of Functional Groups
Organic Synthesis and Estimation of Functional Groups
 
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
Practical Research 1, Lesson 5: DESIGNING A RESEARCH PROJECT RELATED TO DAILY...
 
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdfDr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
Dr.M.Florence Dayana-Cloud Computing-Unit - 1.pdf
 
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
Ideotype concept and climate resilient crop varieties for future- Wheat, Rice...
 

Advanced SQL Webinar

  • 1. Advanced SQL - Tips & Tricks Ram kedem
  • 2. About Me • Data Team Leader at PLYmedia • During the last decade trained thousands of people (Israel and abroad) various topic related to the database world. • Managing an educational website mainly focused on the SQL language • Owner of Ram Kedem Training
  • 3. About this Book • Gathered over a period of almost 10 years • Includes 265 pages and 100 Different complex SQL use-cases • First of its kind in Israel • Aims to provide practical knowledge based on real user experience • Available in Hard-Copy & Online version
  • 4. Goals • Learn real use cases of : • Advanced Scalar Functions • Analytic Functions • Group Functions • Complex Sub-Queries • CTE and Recursive CTE • SET Operators • XML tricks
  • 5. ‫שונים‬ ‫פורומים‬ ‫המנהל‬ ‫אינטרנט‬ ‫לאתר‬,‫שונים‬ ‫משתמשים‬ ‫של‬ ‫ההודעות‬ ‫תוכן‬ ‫את‬ ‫המכילה‬ ‫טבלה‬ ‫קיימת‬. ‫אפליקצייה‬ ‫שגיאות‬ ‫בשל‬ ‫לעיתים‬,‫סימני‬ ‫נכנסים‬ ‫המלל‬ ‫בתוך‬% ‫שונות‬ ‫טכניקות‬ ‫שתי‬ ‫באמצעות‬,‫אחוז‬ ‫מכילים‬ ‫אשר‬ ‫הערכים‬ ‫את‬ ‫מצאו‬)%( 1.‫אחוז‬ ‫עם‬ ‫ערכים‬ ‫מציאת‬
  • 6. 1.‫אחוז‬ ‫עם‬ ‫ערכים‬ ‫מציאת‬ • escape_character • Is a character that is put in front of a wildcard character to indicate that the wildcard should be interpreted as a regular character and not as a wildcard. • escape_character is a character expression that has no default and must evaluate to only one character SELECT * FROM percent_values WHERE id LIKE '%^%%' ESCAPE '^'
  • 7. 1.‫אחוז‬ ‫עם‬ ‫ערכים‬ ‫מציאת‬ • Using square brackets • In MSSQL the square brackets are required if you use keywords or special chars in the column names or identifiers. • For example, You could name a column [First Name] (with a space) • The [ ] in LIKE can be used to specify the % should to be interpreted as a regular character SELECT * FROM percent_values WHERE id LIKE '%[%]%'
  • 8. 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬ ‫הבאות‬ ‫הטבלאות‬ ‫נתונות‬: ‫לקוחות‬ ‫טבלת‬,‫מס‬ ‫לגבי‬ ‫תיאור‬ ‫למצוא‬ ‫ניתן‬ ‫שורה‬ ‫בכל‬'‫הלקוח‬, ‫שמו‬,‫ומס‬'‫מתגורר‬ ‫הוא‬ ‫בה‬ ‫העיר‬ ‫ערים‬ ‫טבלת‬,‫עבור‬ ‫הערים‬ ‫שמות‬ ‫את‬ ‫למצוא‬ ‫ניתן‬ ‫זו‬ ‫בטבלה‬ ‫הלקוחות‬ ‫טבלת‬
  • 9. 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬ ‫העיר‬ ‫את‬ ‫תציג‬ ‫שורה‬ ‫בכל‬ ‫אשר‬ ‫שאילתה‬ ‫כתבו‬,‫בה‬ ‫מתגוררים‬ ‫אשר‬ ‫השונים‬ ‫הלקוחות‬ ‫ואת‬
  • 10. 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬ STUFF() Function • The STUFF function deletes a sequence of characters from a source string and then inserts another sequence of characters into the source string, starting at a specified position. SELECT STUFF('Hello' , 1,1,'B') => Bellow SELECT STUFF('Hello' , 1,2,'B') => Bllo SELECT STUFF('Hello', 2, 2, '**WORLD**') => H**WORLD**lo SELECT STUFF('Hello', 1, 1, '') => ello
  • 11. Correlated Sub Queries VS. Simple Sub Queries • Correlated Subquery is a sub-query that uses values from the outer query. the inner query has to be executed for every row of outer query • Simple subquery doesn't use values from the outer query and is being calculated only once 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬
  • 12. Simple Sub Query SELECT customerName, CityID FROM customers WHERE CityID = (SELECT cityID FROM cities WHERE CityName = 'Tel Aviv') • Inner – what’s the cityID of Tel Aviv ? (only once) • Outer – Display the customerName and CityID for customers whose CityID equals to the output of inner query 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬
  • 13. Correlated Sub Query SELECT CUST.CustomerName, (SELECT CityName FROM Cities CT WHERE CT.CityID = CUST.CityID) FROM customers CUST • Inner – what’s the cityName for the FIRST row in the table ? • Outer – Display the customerName in the FIRST row • Inner – what’s the cityName for the SECOND row in the table ? • Outer – Display the customerName in the SECOND row … 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬
  • 14. For XML Path 1. Get XML element string with FOR XML • Adding FOR XML PATH to the end of a query allows you to output the results of the query as XML elements, with the element name contained in the PATH argument SELECT ',' + CustomerName FROM Customers FOR XML PATH ('') 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬
  • 15. For XML Path 2. Remove leading comma with STUFF • The STUFF statement literally "stuffs” one string into another, replacing characters within the first string. We, however, are using it simply to remove the first character of the resultant list of values. SELECT STUFF ( (SELECT ',' + CustomerName FROM Customers FOR XML PATH ('')) ,1,1,'' ) 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬
  • 16. Putting it all together SELECT CityID, CityName, STUFF ( (SELECT ',' + CustomerName FROM Customers InCust WHERE InCust.CityID = CT.CityID FOR XML PATH ('')) ,1,1,'' ) AS 'Customers' FROM Cities CT 2.‫אחת‬ ‫שורה‬ ‫לתוך‬ ‫ערכים‬ ‫איחוד‬
  • 17. ‫אות‬ ‫לפי‬ ‫מקובצות‬ ‫מסויים‬ ‫במשפט‬ ‫האותיות‬ ‫כמות‬ ‫את‬ ‫מחזירה‬ ‫אשר‬ ‫שאילתה‬ ‫כתבו‬,‫צמד‬ ‫עבור‬ ‫לדוגמא‬ ‫המילים‬: ‫הבאה‬ ‫התוצאה‬ ‫תתקבל‬ 3.‫במשפט‬ ‫תווים‬ ‫כמות‬ ‫הצגת‬
  • 18. CTE Basics • A common table expression (CTE) can be thought of as a temporary result set that is defined within the execution scope of a single SELECT, INSERT, UPDATE, DELETE, or CREATE VIEW statement • Using a CTE offers the advantages of improved readability and ease in maintenance of complex queries. • The query can be divided into separate, simple, logical building blocks. These simple blocks can then be used to build more complex, interim CTEs until the final result set is generated. 3.‫במשפט‬ ‫תווים‬ ‫כמות‬ ‫הצגת‬
  • 19. ;WITH [CountCustomers] (col1, col2) AS ( SELECT COUNT(*) CNT , CityID FROM customers GROUP BY CityID ) SELECT * FROM [CountCustomers] 3.‫במשפט‬ ‫תווים‬ ‫כמות‬ ‫הצגת‬ CTE name Column names CTE name Actual Query
  • 20. ;WITH "Numbers" (id) AS ( SELECT 1 UNION ALL SELECT id + 1 FROM "Numbers" WHERE id < 20 ) SELECT * FROM "Numbers" 3.‫במשפט‬ ‫תווים‬ ‫כמות‬ ‫הצגת‬ CTE name Column name CTE name Anchor query (runs once and the results ‘seed’ the Recursive query) Recursive query (runs multiple times and is the criteria for the remaining results) UNION ALL statement to bind the Anchor and Recursive queries together.
  • 21. WITH "wordlen"(id) AS ( SELECT 1 UNION ALL SELECT id + 1 FROM "wordlen" WHERE id < (SELECT LEN('hello world')) ) SELECT letter, COUNT(letter) FROM ( SELECT SUBSTRING('hello world' , id , 1) letter FROM "wordlen" WHERE SUBSTRING('hello world' , id , 1) <> ' ' ) in_tab GROUP BY letter ORDER BY letter 3.‫במשפט‬ ‫תווים‬ ‫כמות‬ ‫הצגת‬
  • 22. ‫שונים‬ ‫יוזרים‬ ‫של‬ ‫המלאים‬ ‫שמותיהם‬ ‫את‬ ‫המכילה‬ ‫טבלה‬ ‫נתונה‬(‫פרטי‬ ‫שם‬,‫אמצעי‬ ‫שם‬,‫משפחה‬ ‫ושם‬.)‫ליוזרים‬ ‫אמצעי‬ ‫שם‬ ‫קיים‬ ‫לא‬ ‫מסויימים‬,‫בלבד‬ ‫משפחתו‬ ‫ושם‬ ‫הפרטי‬ ‫שמו‬ ‫יופיעו‬ ‫אלו‬ ‫במקרים‬.‫את‬ ‫עדכן‬ ‫לא‬ ‫יוזר‬ ‫לעיתים‬ ‫משפחתו‬ ‫שם‬ ‫ואת‬ ‫האמצעי‬ ‫שמו‬,‫בלבד‬ ‫הפרטי‬ ‫שמו‬ ‫יופיע‬ ‫אלו‬ ‫במקרים‬. 4.‫בעמודה‬ ‫מילים‬ ‫פיצול‬
  • 23. ‫הפרטי‬ ‫שמו‬ ‫את‬ ‫שונות‬ ‫בעמודות‬ ‫המציגה‬ ‫שאילה‬ ‫כתבו‬,‫האמצעי‬ ‫שמו‬,‫מהיוזרים‬ ‫אחד‬ ‫כל‬ ‫של‬ ‫משפחתו‬ ‫ושם‬. ‫האמצעי‬ ‫והשם‬ ‫במידה‬‫מופיע‬ ‫לא‬ ‫המשפחה‬ ‫שם‬,‫יוצג‬NULL. 4.‫בעמודה‬ ‫מילים‬ ‫פיצול‬
  • 24. REVERSE () • Returns the reverse order of a string value. • SELECT REVERSE('Hello') => 'Olleh' REPLACE () • Replaces all occurrences of a specified string value with another string value. • SELECT REPLACE('Hello World','World','SQL') => 'Hello SQL' PARSENAME () • Returns the specified part of an object name • SELECT PARSENAME('Word1.Word2.Word3.Word4',1) => 'Word4' 4.‫בעמודה‬ ‫מילים‬ ‫פיצול‬
  • 25. SELECT REVERSE('Hello,World') SELECT REPLACE(REVERSE('Hello,World'),',','.') SELECT PARSENAME(REPLACE(REVERSE('Hello,World'),',','.'),1) SELECT REVERSE(PARSENAME(REPLACE(REVERSE('Hello,World'),',','.'),1)) 4.‫בעמודה‬ ‫מילים‬ ‫פיצול‬ dlroW,olleH dlroW.olleH olleH Hello
  • 26. SELECT FirstName, CASE WHEN lastName IS NULL THEN NULL ELSE MiddleName END AS MiddleName, CASE WHEN LastName IS NULL THEN MiddleName ELSE LastName END AS LastName FROM ( SELECT Reverse(ParseName(Replace(Reverse(username), ' ', '.'), 1)) As FirstName , Reverse(ParseName(Replace(Reverse(username), ' ', '.'), 2)) As MiddleName , Reverse(ParseName(Replace(Reverse(username), ' ', '.'), 3)) As LastName FROM users ) IN_TAB 4.‫בעמודה‬ ‫מילים‬ ‫פיצול‬ If there is no value in lastName then middleName is actually NULL If there is no value in lastName then middleName is actually lastName putting it all together
  • 27. ‫הבאה‬ ‫הטבלה‬ ‫נתונה‬.‫במערכת‬ ‫תקלה‬ ‫התרחשה‬ ‫בהם‬ ‫תאריכים‬ ‫תיעוד‬ ‫למצוא‬ ‫ניתן‬ ‫זו‬ ‫בטבלה‬.‫כי‬ ‫לראות‬ ‫ניתן‬ ‫שגיאה‬ ‫בין‬1‫מס‬ ‫לשגיאה‬'2‫יומיים‬ ‫עברו‬,‫שגיאה‬ ‫בין‬2‫לשגיאה‬3‫עברו‬6‫ימים‬,‫הלאה‬ ‫וכן‬ ‫לשגיאה‬ ‫שגיאה‬ ‫בין‬ ‫הממוצע‬ ‫הימים‬ ‫מספר‬ ‫את‬ ‫מחזירה‬ ‫אשר‬ ‫שאילתה‬ ‫כתבו‬ 5.‫ממוצעים‬ ‫זמנים‬ ‫חישוב‬
  • 28. 5.‫ממוצעים‬ ‫זמנים‬ ‫חישוב‬ LEAD() Function • LEAD provides access to a row at a given physical offset that follows the current row. Use this analytic function in a SELECT statement to compare values in the current row with values in a following row Basic Usage • LEAD(column_name) OVER (ORDER BY column_name)
  • 29. 5.‫ממוצעים‬ ‫זמנים‬ ‫חישוב‬ Putting it all together SELECT AVG(DIFF) AVG_DIFF FROM ( SELECT id, fdate, ISNULL(DATEDIFF(day, fdate, LEAD(fdate) OVER (ORDER BY id)),0) DIFF FROM FailuresLog ) IN_TAB
  • 30. ‫הבאה‬ ‫הצבעים‬ ‫טבלת‬ ‫נתונה‬,‫זוגי‬ ‫סידורי‬ ‫מספר‬ ‫תחת‬ ‫מופיעים‬ ‫הלבנים‬ ‫הצבעים‬ ‫כי‬ ‫לראות‬ ‫ניתן‬,‫והצבעים‬ ‫אי‬ ‫סידורי‬ ‫מספר‬ ‫תחת‬ ‫מופיעים‬ ‫השחורים‬-‫זוגי‬. ‫באמצעות‬6‫שונות‬ ‫טכניקות‬,‫הצבעים‬ ‫בין‬ ‫המחליפה‬ ‫שאילתה‬ ‫כתבו‬(‫מספר‬ ‫תחת‬ ‫יופיעו‬ ‫השחורים‬ ‫הצבעים‬ ‫זוגי‬ ‫סידורי‬,‫אי‬ ‫סידורי‬ ‫מספר‬ ‫תחת‬ ‫יופיעו‬ ‫הלבנים‬ ‫והצבעים‬-‫זוגי‬) 6.‫מותנית‬ ‫להחלפה‬ ‫מתודות‬
  • 31. 6.‫מותנית‬ ‫להחלפה‬ ‫מתודות‬ -- 1. CASE SELECT cid, CASE WHEN cdesc = 'black' THEN 'white' ELSE 'black' END cdesc FROM colors -- 2. REPLACE SELECT cid, REPLACE (cdesc, 'black', 'white') FROM colors WHERE cdesc = 'black' UNION ALL SELECT cid, REPLACE (cdesc, 'white', 'black') FROM colors WHERE cdesc = 'white' ORDER BY 1 -- 3. IIF SELECT IIF(cdesc = 'white' , 'black' , 'white') FROM colors
  • 32. 6.‫מותנית‬ ‫להחלפה‬ ‫מתודות‬ -- 4. SUBQUERY SELECT cid, (SELECT DISTINCT cdesc FROM colors in_tbl WHERE cdesc <> out_tbl.cdesc) FROM colors out_tbl -- 5. JOIN SELECT c1.cid, c2.cdesc FROM colors c1 JOIN (SELECT DISTINCT cdesc FROM colors) c2 ON c1.cdesc <> c2.cdesc ORDER BY 1 -- 6. ISNULL / NULLIF SELECT cid, ISNULL(NULLIF('white', cdesc), 'black') FROM colors
  • 33. Advanced SQL Course • Will take place between March 21 and 28 at John-Bryce Tel-Aviv • 3 Meetings, 17:30-21:00 • More details can be found here
  • 34. Thanks ! keep in touch Ram Kedem ram.kdm@gmail.com Facebook Linkedin ramkedem.com