I WANT TO HOLD YOUR HAND 1ST TOP 100 SINGLE 1964.01.18.

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

Ashley Ohmann June 20, * What is Custom SQL? * What can I do with it? * Join conditions * Unions and Self Joins * Ranks * Derived Tables.
Exploring Microsoft Access
5.1Database System Concepts - 6 th Edition Chapter 5: Advanced SQL Advanced Aggregation Features OLAP.
Chapter 11 Group Functions
Introduction to Structured Query Language (SQL)
Implementing Business Analytics with MDX Chris Webb London September 29th.
©Silberschatz, Korth and Sudarshan22.1Database System Concepts 4 th Edition 1 Extended Aggregation SQL-92 aggregation quite limited  Many useful aggregates.
Copyright: Silberschatz, Korth and Sudarshan 1 OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL: same as SQL:1999.
Introduction to Structured Query Language (SQL)
Concepts of Database Management Sixth Edition
ADVANCE T-SQL: WINDOW FUNCTIONS Rahman Wehelie 7/16/2013 ITC 226.
The Model Clause explained Tony Hasler, UKOUG Birmingham 2012 Tony Hasler, Anvil Computer Services Ltd.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
Exploring Office Grauer and Barber 1 Committed to Shaping the Next Generation of IT Experts. Chapter 3 - Information From the Database: Reports.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Mark Inman U.S. Navy (Naval Sea Logistics Center) Session #213 Analytic SQL for Beginners.
Programming in R SQL in R. Running SQL in R In this session I will show you how to: Run basic SQL commands within R.
Chapter 3 Query and Report. Agenda Report types Report contents Report creation Report design view Query and dynaset Function and grouping Action query.
T-SQL: Simple Changes That Go a Long Way DAVE ingeniousSQL.com linkedin.com/in/ingenioussql.
More Windowing Functions KEVIN MCCARTY. What are Windowing Functions Again? Introduced in SQL Server 2005 (SQL 2003 Standard) Used to provide operations.
Structured Query Language SQL Unit 2 An Introduction to Organizing and Retrieving Data with SQL.
How to train your users to create their own BI reports? So that you (IT) don’t have to Paras Doshi Consultant, SolidQ Chapter co-leader, PASS Business.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
A Guide to SQL, Eighth Edition Chapter Six Updating Data.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Random Query Generator for Hive November 2015 Hive Contributor Meetup Szehon Ho.
Background Lots of Demos(That’s it.)
©Silberschatz, Korth and Sudarshan5.1Database System Concepts - 6 th Edition Recursive Queries.
A Glance at the Window Functions. Window Functions Introduced in SQL 2005 Enhanced in SQL 2012 So-called because they operate on a defined portion of.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
1 SQL Chapter 9 – 8 th edition With help from Chapter 2 – 10 th edition.
LM 5 Introduction to SQL MISM 4135 Instructor: Dr. Lei Li.
 CONACT UC:  Magnific training   
DBI309: Using SQL Server 2012 Window Functions to Solve Common T-SQL Challenges Steven Wang MCITP – BI, Database Developer and DBA.
Relational Databases Today we will look at: Different ways of searching a database Creating queries Aggregate Queries More complex queries involving different.
IFS180 Intro. to Data Management Chapter 10 - Unions.
VICTORIA UNIVERSITY OF WELLINGTON Te Whare Wananga o te Upoko o te Ika a Maui SWEN 432 Advanced Database Design and Implementation OLAP Queries and SQL:1999.
Eugene Meidinger Intermediate Querying: Going Beyond Select
T-SQL Power! Windows That Open Doors Adam
Data Analysis with SQL Window Functions Adam McDonald IT Architect / Senior SQL Developer Smith Travel
An Introduction to Business Intelligence
Analytic Window Functions
Lecturer : Dr. Pavle Mogin
Using Partitions and Fragments
T-SQL: Simple Changes That Go a Long Way
T-SQL: Simple Changes That Go a Long Way
Data Analysis with SQL Window Functions
Window function performance
Chapter 5: Advanced SQL Database System concepts,6th Ed.
Using Window Ranking, Offset, and Aggregate Functions
SQL FUNDAMENTALS CDSE Days 2018.
Discovering SSRS 2016 in Azure: Dataset to Deployment
T-SQL Power! The OVER Clause: Your Key to No-Sweat Problem Solving
T-SQL Window Function Deep Dive part 1
CSCI 2141 – Intro to Database Systems
WELCOME Howzit Sawubona.
Writing Better Queries with Window Functions
Oracle8i Analytical SQL Features
Chapter 4 Summary Query.
T-SQL Window function deep dive part 2
Introduction to Window Functions
Data Analysis with SQL Window Functions
Introduction to T-sql Window functionS
CS240B: Assignment1 Winter 2016.
OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL: same as SQL:1999.
Slides based on those originally by : Parminder Jeet Kaur
Chapter 3 Query and Report.
T-SQL: Simple Changes That Go a Long Way
Presentation transcript:

I WANT TO HOLD YOUR HAND 1ST TOP 100 SINGLE 1964.01.18

A legacy of astonishing dominance The Beatles in the Top 100 A legacy of astonishing dominance 585 313 68 19 Over more than 32 years, The Beatles had 585 entries in the Billboard Top 100. In that time, at least one song by the Beatles was on the Top 100 chart in 313 different weeks. John, Paul, George and Ringo produced 68 different songs which spent time in the Billboard Top 100. From I Want to Hold Your Hand to The Long and Winding Road, 19 different Beatles singles spent at least a week on top of the charts.

WINDOWING FUNCTIONS SHEDDING SOME LIGHT

James McGillivray / BI Architect About Me Hey Jude James Professional 10 Years BI Experience Microsoft Certified SQL User Group Johannesburg, South Africa Personal Sport: Cricket, Soccer, Squash, Running Slowly. Culture: Symphony Choir of Johannesburg, Musical Theatre Other: Board Games, Poker James McGillivray / BI Architect @JamesMcG_MSBI TheJimmyRSA

The Long and Winding Road Where we’re going What Goes On SESSION OBJECTIVES INTRODUCTION TO WINDOWING FUNCTIONS Do You Want To Know A Secret THE OVER CLAUSE

The Long and Winding Road Where we’re going What Goes On SESSION OBJECTIVES INTRODUCTION TO WINDOWING FUNCTIONS Do You Want To Know A Secret THE OVER CLAUSE

Eight Days a Week With a Little Help From My Friends Yesterday RANKING FUNCTIONS AND ORDER BY With a Little Help From My Friends PARTITION BY Yesterday LEAD AND LAG ROWS AND RANGES Come Together GROUP BY

Eight Days a Week With a Little Help From My Friends Yesterday RANKING FUNCTIONS AND ORDER BY With a Little Help From My Friends PARTITION BY Yesterday LEAD AND LAG ROWS AND RANGES Come Together GROUP BY

You Can’t Do That RESTRICTIONS Help QUESTIONS

Visualise the Concepts Demonstrate the Functionality Session Objectives Learn the Syntax We’ll go through each clause available in Windowing functions, building from simplest to most complex Visualise the Concepts Demonstrate the Functionality After each clause is explained, see it demonstrated in an abstract but simple way. See the incredible power of the functions as we explore the music of THE BEATLES. WHAT GOES ON

Introduction to Windowing Functions Introduced in SQL 2012 Although RANKING functions already existed Ranking, Aggregation, Analytical Windowing functions reduce query complexity for common patterns Avoid Self-Joins Many queries can get rid of self-joins by using windowing functions WHAT GOES ON

Introduction to Windowing Functions 10 50 100 1000 1 5 9 13 20 100 150 100 2 6 10 14 30 200 200 50 3 7 11 15 40 50 1000 50 4 8 12 16 Demo Table (RowID, Colour, Value) WHAT GOES ON

The Over Clause Aggregations without Group By? Aggregation is performed OVER all rows in the data set Add Information Result Set Use data from the entire data set on each row in the set Totals Calculate totals over the set. Total # of Weeks Beatles songs spent on chart. Other Uses % of Total Average of Entire Set Do You Want To Know A Secret?

The Over Clause count(*) over () 16 Do You Want To Know A Secret? 10 50 100 1000 16 20 100 150 100 30 200 200 50 40 50 1000 50 count(*) over () Do You Want To Know A Secret?

The Over Clause sum(Value) over () Do You Want To Know A Secret? 3150 10 50 100 1000 3150 20 100 150 100 30 200 200 50 40 50 1000 50 sum(Value) over () Do You Want To Know A Secret?

The Over Clause DEMO Do You Want To Know A Secret?

Ranking Functions and the Order By Clause Position of Current Row in Set Must have an order by to determine sorting row_number() Ignore ties. Specify multiple columns in order by to avoid unexpected behaviour rank() Assign ties the same value. Skip values after ties dense_rank() Assign ties the same value. Do not skip value after ties. EIGHT DAYS A WEEK

Ranking Functions and the Order By Clause 10 50 100 1000 1 5 10 16 20 100 150 100 2 9 12 11 30 200 200 50 3 13 14 7 40 50 1000 50 4 6 15 8 row_number() over (order by VALUE) EIGHT DAYS A WEEK

Ranking Functions and the Order By Clause 10 50 100 1000 1 7 10 16 20 100 150 100 2 9 12 11 30 200 200 50 3 13 14 8 40 50 1000 50 4 6 15 5 row_number() over (order by VALUE) EIGHT DAYS A WEEK

Ranking Functions and the Order By Clause 10 50 100 1000 1 1 8 12 20 100 150 100 1 6 8 14 30 200 200 50 1 6 8 14 40 50 1000 50 1 8 12 14 rank() over (order by COLOUR) EIGHT DAYS A WEEK

Ranking Functions and the Order By Clause 10 50 100 1000 1 1 3 4 20 100 150 100 1 2 3 5 30 200 200 50 1 2 3 5 40 50 1000 50 1 3 4 5 dense_rank() over (order by COLOUR) EIGHT DAYS A WEEK

Ranking Functions and the Order By Clause DEMO EIGHT DAYS A WEEK

The Partition By Clause Split the data into groups Perform aggregation over the partitions Sub-Totals Totals per Category Other Uses Percentage of Sub-Total Ranking within group WITH A LITTLE HELP FROM MY FRIENDS

The Partition By Clause 10 50 100 1000 150 150 500 2000 20 100 150 100 150 300 500 250 30 200 200 50 150 300 500 250 40 50 1000 50 150 500 2000 250 sum(VALUE) over (partition by COLOUR) WITH A LITTLE HELP FROM MY FRIENDS

The Partition By Clause 10 50 100 1000 1 5 2 2 20 100 150 100 2 1 3 3 30 200 200 50 3 2 4 2 40 50 1000 50 4 1 1 1 row_number() over (partition by COLOUR order by VALUE) WITH A LITTLE HELP FROM MY FRIENDS

The Partition By Clause DEMO WITH A LITTLE HELP FROM MY FRIENDS

LEAD and LAG/ROWS and RANGES Order data within groups Must use the Order By clause with ROWS Calculate relative to row order All before this row. 1 after this row etc. Analysis within subset of partition Previous 3 Months Average Sales Year-on-Year Variance WITH A LITTLE HELP FROM MY FRIENDS

LEAD and LAG 10 50 100 1000 NULL 40 50 1000 20 100 150 100 10 NULL 100 NULL 30 200 200 50 20 100 150 100 40 50 1000 50 30 NULL NULL 50 lag(VALUE,1,NULL) over (partition by COLOUR order by ROWID) WITH A LITTLE HELP FROM MY FRIENDS

LEAD and LAG DEMO WITH A LITTLE HELP FROM MY FRIENDS

ROWS and RANGES sum(VALUE) over (partition by COLOUR order by POSITION 10 50 100 1000 10 150 150 2000 20 100 150 100 30 100 300 100 30 200 200 50 60 300 500 150 40 50 1000 50 100 50 1000 200 sum(VALUE) over (partition by COLOUR order by POSITION ROWS UNBOUNDED PRECEDING) WITH A LITTLE HELP FROM MY FRIENDS

ROWS and RANGES 10 50 100 1000 10 90 150 2000 20 100 150 100 30 100 250 100 30 200 200 50 50 300 350 150 40 50 1000 50 70 50 1000 100 sum(VALUE) over (partition by COLOUR order by POSITION ROWS BETWEEN 1 PRECEDING AND CURRENT ROW) WITH A LITTLE HELP FROM MY FRIENDS

ROWS and RANGES DEMO WITH A LITTLE HELP FROM MY FRIENDS

Group By Aggregations of Aggregations COME TOGETHER Perform windowing functions on Aggregations SUM(COUNT()) MAX(AVG()) COME TOGETHER

Group By DEMO COME TOGETHER

Restrictions YOU CAN’T DO THaT

Restrictions Only in Select Statement YOU CAN’T DO THaT No where row_order() = 1 YOU CAN’T DO THaT

Should I have called this slide Questions Questions Should I have called this slide FROM ME TO YOU? @JamesMcG_MSBI TheJimmyRSA HELP