A Linear Regression Algorithm Using Windowing Functions KEVIN MCCARTY.

Slides:



Advertisements
Similar presentations
SQL – Lesson II Grade 12.
Advertisements

Ashley Ohmann June 20, * What is Custom SQL? * What can I do with it? * Join conditions * Unions and Self Joins * Ranks * Derived Tables.
Michael Pizzo Software Architect Data Programmability Microsoft Corporation.
Module 7 Designing Queries for Optimal Performance.
Distributed Databases Logical next step in geographically dispersed organisations goal is to provide location transparency starting point = a set of decentralised.
Access Tutorial 3 Maintaining and Querying a Database
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 3 1 Microsoft Office Access 2003 Tutorial 3 – Querying a Database.
Querying a Database Microsoft Office Access 2003.
Putting the Sting in Hive Page 1 Alan F.
Using Relational Databases and SQL Department of Computer Science California State University, Los Angeles Lecture 8: Subqueries.
Maintaining and Querying a Database Microsoft Access 2010.
Version 1.0. MCAD MCSD MCPD Enterprise SQL MCTS MCT Software/Web Development Consultant Cryptography/Digital Signature Consultant SQL Server 2005/2008R2/2012.
You can use a query to view a subset of your data or to answer questions about your data. For example, if you want to view a list of student names and.
2 Overview of SSIS performance Troubleshooting methods Performance tips.
Introduction to SQL Steve Perry
ADVANCE T-SQL: WINDOW FUNCTIONS Rahman Wehelie 7/16/2013 ITC 226.
MySQL By Scott Halvorson WDTC/DPG ATEC Forecasters Conference Boulder Colorado 25 July 2006.
1.NET Web Forms Business Forms © 2002 by Jerry Post.
® Microsoft Office 2010 Access Tutorial 3 Maintaining and Querying a Database.
Mark Inman U.S. Navy (Naval Sea Logistics Center) Session #213 Analytic SQL for Beginners.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
SQL-5 (Group By.. Having). Group By  Need: To apply the aggregate functions to subgroups of tuples in a relation, where the subgroups are based on some.
COMPREHENSIVE Access Tutorial 3 Maintaining and Querying a Database.
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.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
XP New Perspectives on Microsoft Access 2002 Tutorial 31 Microsoft Access 2002 Tutorial 3 – Querying a Database.
05 | SET Operators, Windows Functions, and Grouping Brian Alderman | MCT, CEO / Founder of MicroTechPoint Tobias Ternstrom | Microsoft SQL Server Program.
DAY 18: MICROSOFT ACCESS – CHAPTER 3 CONTD. Akhila Kondai October 21, 2013.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
Background Lots of Demos(That’s it.)
Sofia, Bulgaria | 9-10 October SQL Querying Tips & Techniques Richard Campbell.
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.
Unit-8 Introduction Of MySql. Types of table in PHP MySQL supports various of table types or storage engines to allow you to optimize your database. The.
HRP Copyright © Leland Stanford Junior University. All rights reserved. Warning: This presentation is protected by copyright law and.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
DBI309: Using SQL Server 2012 Window Functions to Solve Common T-SQL Challenges Steven Wang MCITP – BI, Database Developer and DBA.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
IFS180 Intro. to Data Management Chapter 10 - Unions.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
T-SQL Power! Windows That Open Doors Adam
Data Analysis with SQL Window Functions Adam McDonald IT Architect / Senior SQL Developer Smith Travel
Web Systems & Technologies
Implementing Views Advanced Database Dr. AlaaEddin Almabhouh.
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
JDBC.
Module 7: Implementing Views
Using Window Ranking, Offset, and Aggregate Functions
I WANT TO HOLD YOUR HAND 1ST TOP 100 SINGLE
Microsoft Office Access 2003
T-SQL Power! The OVER Clause: Your Key to No-Sweat Problem Solving
T-SQL Window Function Deep Dive part 1
Writing Better Queries with Window Functions
Tutorial 3 – Querying a Database
Oracle8i Analytical SQL Features
Microsoft Office Access 2003
Chapter 4 Summary Query.
Tally Ho! -- Explore the Varied Uses of Tally Tables
T-SQL Window function deep dive part 2
Introduction to Window Functions
Data Analysis with SQL Window Functions
Introduction to T-sql Window functionS
Introduction to Access
Power Query & Database Tuning
OLAP Functions Order-Dependent Aggregates and Windows in SQL: SQL: same as SQL:1999.
T-SQL: Simple Changes That Go a Long Way
Presentation transcript:

A Linear Regression Algorithm Using Windowing Functions KEVIN MCCARTY

What are Windowing Functions Introduced in SQL Server 2005 Used to add artificial values to a set in order to provide a specific ordering of rows ◦This was a difficult operation before, requiring liberal use of temp tables and a lot of code ◦Combines a “ranking” function with the OVER clause The ranking functions are: ◦ROW_NUMBER ◦RANK ◦DENSE_RANK ◦NTILE Windowing functions can work on individual rows or as part of an aggregate query. There are aggregate, ranking, distribution and offset functions – but we will only deal with ranking functions today 

What The Ranking Functions Do ROW_NUMBER – Based upon the order, attaches an ascending row value, similar to an identity RANK – Attaches an ascending row value based upon order, applying similar values to ties, in which case introduces gaps in the rank DENSE_RANK – Similar to RANK except it does not introduce gaps NTILE(n) – Splits data into subsets or groups and numbers each subgroup accordingly

The OVER clause Use the OVER clause to define the “window” or specific set of rows to apply the windowing function ◦OVER must be combined with an ORDER BY clause (which makes sense) SELECT BusinessEntityID AS SalesID, FirstName + ' ' + LastName AS FullName, SalesLastYear, ROW_NUMBER() OVER(ORDER BY SalesLastYear ASC) AS RowNumber FROM Sales.vSalesPerson;

Windowing Components Conceptual relationship between window elements: Result set (OVER) Window partition (PARTITION BY) Frame (ROWS BETWEEN) Note: Shameless theft from Microsoft courseware

Basic Syntax OVER ( [ ] -- optional [ ] [ ] - optional ) SELECT BusinessEntityID AS SalesID, FirstName + ' ' + LastName AS FullName, SalesLastYear, ROW_NUMBER() OVER(ORDER BY SalesLastYear ASC) AS RowNumber FROM Sales.vSalesPerson;

Partitioning Use Partitioning to limit sets of rows to those with the same value in a partitioning column ◦Another term for this is “framing” ◦Useful for isolating sets with specific characteristics without having to run a separate query SELECT BusinessEntityID AS SalesID, FirstName + ' ' + LastName AS FullName, SalesLastYear, TerritoryGroup, ROW_NUMBER() OVER(PARTITION BY TerritoryGroup ORDER BY SalesLastYear ASC) AS RowNumber FROM Sales.vSalesPerson;

Ranking Functions in Action

A Linear Regression Algorithm Fuzzy logic routines are often combined with optimization techniques

Why Use Ranking Functions? In this case, we have a fuzzy car driving around a track It’s goal is to navigate the track without hitting the sides Sometimes fuzzy algorithm is bad and needs to be fixed Other times algorithm is OK but can be better So how to optimize?

Why Use Ranking Functions? Note all the back-and-forth maneuvering. If we can reduce that we can optimize the car’s path. Linear regression allows us to determine a more optimal path The new path now becomes a “goal” for the algorithm Use genetic/memetic algorithm to tweak algorithm ◦In which case the “goal” becomes the fitness function Ranking functions allow us to do this as a set-based Operation instead of point-by-point. ◦Faster and easier too

Boring Explanation Use the second derivative to get a brute-force linear regression The tricky part is finding true peaks and valleys in the data This is where ranking functions come in