﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by Wayne Sheffield  / The new Analytic functions in SQL Server 2012 / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 19:19:44 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]zombieisdead2020 (1/29/2013)[/b][hr]I see first_value and last_value function, but do not see second or third value function!How can I write for example second_value() function by using analytical window function?[/quote]You will probably have to revert to the ROW_NUMBER() function, then look for where ROW_NUMBER() = 2, 3, etc.</description><pubDate>Tue, 29 Jan 2013 21:29:28 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>I see first_value and last_value function, but do not see second or third value function!How can I write for example second_value() function by using analytical window function?</description><pubDate>Tue, 29 Jan 2013 12:07:00 GMT</pubDate><dc:creator>zombieisdead2020</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Great article Wayne, thanks.</description><pubDate>Tue, 24 Jan 2012 06:01:42 GMT</pubDate><dc:creator>Koen Verbeeck</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Great article Wayne!Thanks for sharing.</description><pubDate>Sun, 22 Jan 2012 16:58:46 GMT</pubDate><dc:creator>spaghettidba</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Now if only we could get 2012 on our production boxes before 2020. So excited for SS2012</description><pubDate>Sat, 21 Jan 2012 16:24:06 GMT</pubDate><dc:creator>Gabe T.</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Wonderful article, Wayne.  The charts summarize a nicely laid out and well written article and make it real easy to get extra information.  Thanks for taking the time to write a class article!</description><pubDate>Fri, 20 Jan 2012 09:56:04 GMT</pubDate><dc:creator>Jeff Moden</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]WayneS (1/19/2012)[/b][hr]Actually...this article only talks about the Analytic functions. You might want to look at my previous article [url=http://www.sqlservercentral.com/articles/T-SQL/75466/][u]The OVER Clause enhancements in SQL Server code named “Denali”, CTP3[/u][/url].Basically, the MIN/MAX functions DO allow you to order your partition by a different column. But let's talk about this "over there"... it's more appropriate there.[/quote]Thanks for your link the the other article. I was not aware that these were also upgraded.</description><pubDate>Fri, 20 Jan 2012 00:53:25 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Jason, Geoff, Mark, Tim and KWymore...Thanks, I'm very glad that you'll like it.</description><pubDate>Thu, 19 Jan 2012 19:53:25 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]  Jack Corbett (1/19/2012)[/b][hr]Good article Wayne.  One thing I like to see in articles like this though is how you might solve the same problem without using the new functions.  Just to see how much the new functions help.[/quote]Thanks Jack. That is a very good idea... I'll have to keep it in mind.</description><pubDate>Thu, 19 Jan 2012 19:51:43 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]Zeev Kazhdan (1/19/2012)[/b][hr]Finally they [b]will[/b] have what Oracle [b]had[/b] delivered ages ago....[/quote]and MySql, and DB2, and... well, nearly everyone else. It is long overdue, and should have been in 2008.</description><pubDate>Thu, 19 Jan 2012 19:48:57 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]j-1064772 (1/19/2012)[/b][hr]How do the newfangled Analytics functions compare with the Quirky Update method used for - among other things - creating running totals in term of performance ?[/quote]The Analytic functions don't, but the OVER clause enhancements allows running totals with the SUM() function and the enhanced OVER clause. See my previous article: [url=http://www.sqlservercentral.com/articles/T-SQL/75466/][u]The OVER Clause enhancements in SQL Server code named “Denali”, CTP3.[/u][/url] You might also want to see my blog post on this: [url=http://blog.waynesheffield.com/wayne/archive/2011/08/running-totals-in-denali-ctp3/][u]http://blog.waynesheffield.com/wayne/archive/2011/08/running-totals-in-denali-ctp3/[/u][/url]. In short, the QU still wins, but the newly enhanced OVER clause beats everything else.Did you click the "TSQL Challenges Winner" icon in my signature? It beat everything else quite handily doing a running total challenge.</description><pubDate>Thu, 19 Jan 2012 19:47:47 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]RichB (1/19/2012)[/b][hr]Any idea what the performance of these things is like?[/quote]Did you click on that "TSQL Challenges Winner" icon in my signature? (Well, that is using the aggregate functions and not the analytic, but I believe them to be similar.)</description><pubDate>Thu, 19 Jan 2012 19:42:09 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]Christian Buettner-167247 (1/19/2012)[/b][hr][quote][b]WayneS (1/18/2012)[/b][hr]Comments posted to this topic are about the item [B]&amp;lt;A HREF="/articles/SQL+Server+2012/76704/"&amp;gt;The new Analytic functions in SQL Server 2012&amp;lt;/A&amp;gt;[/B][/quote]Great information, thanks for that.To me it was not clear immediately, what the difference between the MAX Aggregate Window Function and LAST_VALUE(X) was. In the end [code="sql"]MAX(x) OVER (PARTITION BY y)[/code] should return the same as  [code="sql"]FIRST_VALUE(X) OVER (PARTITION BY Y, ORDER BY X DESC)[/code]But obviously, the MAX / MIN Aggregate Window Functions do not allow you to order your partition by a different column before applying the aggregate. (And it actually does not really make sense to impose a different order on MAX or MIN.)So the whole point of FIRST_VALUE and LAST_VALUE seem to be:[code="sql"]FIRST_VALUE(X) OVER (PARTITION BY Y, ORDER BY [b]SomeOtherColumn[/b] DESC)[/code]Any other points I may have missed?[/quote]Actually...this article only talks about the Analytic functions. You might want to look at my previous article [url=http://www.sqlservercentral.com/articles/T-SQL/75466/][u]The OVER Clause enhancements in SQL Server code named “Denali”, CTP3[/u][/url].Basically, the MIN/MAX functions DO allow you to order your partition by a different column. But let's talk about this "over there"... it's more appropriate there.</description><pubDate>Thu, 19 Jan 2012 19:40:45 GMT</pubDate><dc:creator>WayneS</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Nice article, very helpful. It's nice to see articles like this with examples. Definitely helps to prove to others why upgrades are needed. :)</description><pubDate>Thu, 19 Jan 2012 15:27:29 GMT</pubDate><dc:creator>KWymore</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Thanks - this is a great summary.</description><pubDate>Thu, 19 Jan 2012 13:22:59 GMT</pubDate><dc:creator>tim.hulse</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>How do the newfangled Analytics functions compare with the Quirky Update method used for - among other things - creating running totals in term of performance ?</description><pubDate>Thu, 19 Jan 2012 13:14:36 GMT</pubDate><dc:creator>j-1064772</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Thank you for this Wayne - I'll definitely come back to it later.  I like your concise writing style with helpful examples too.  - Mark</description><pubDate>Thu, 19 Jan 2012 12:41:25 GMT</pubDate><dc:creator>mtillman-921105</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Good article Wayne.  One thing I like to see in articles like this though is how you might solve the same problem without using the new functions.  Just to see how much the new functions help.</description><pubDate>Thu, 19 Jan 2012 08:30:24 GMT</pubDate><dc:creator>  Jack Corbett</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>PERCENTILE_CONT / PERCENTILE_DISC Lets recall from statistics that continuous variables (PERCENTILE_CONT) are those that "cannot not be exactly counted," while discrete variables (PERCENTILE_DISC) "have an exact amount."PERCENTILE_CONT would be better used when performing estimation or predictive calculations, as you are trying to determine a value from a sample of data (where the entire data set is unknown).PERCENTILE_DISC would be better for when we need an exact measure, and the entire data set is known.**Note: I am not a statistician, nor an analytics guru, so hopefully someone with greater experience could shine some better light on this, or at least validate my statement. Hopefully this helps some trying to understand the purposes behind these functions.Stephen</description><pubDate>Thu, 19 Jan 2012 08:24:53 GMT</pubDate><dc:creator>stephen99999</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Great article Wayne. This is great info to have when management wants to know why we are always upgrading :-D</description><pubDate>Thu, 19 Jan 2012 08:14:18 GMT</pubDate><dc:creator>Geoff A</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Good Stuff Wayne</description><pubDate>Thu, 19 Jan 2012 07:55:42 GMT</pubDate><dc:creator>SQLRNNR</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Any idea what the performance of these things is like?</description><pubDate>Thu, 19 Jan 2012 06:48:25 GMT</pubDate><dc:creator>RichB</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>[quote][b]WayneS (1/18/2012)[/b][hr]Comments posted to this topic are about the item [B]&amp;lt;A HREF="/articles/SQL+Server+2012/76704/"&amp;gt;The new Analytic functions in SQL Server 2012&amp;lt;/A&amp;gt;[/B][/quote]Great information, thanks for that.To me it was not clear immediately, what the difference between the MAX Aggregate Window Function and LAST_VALUE(X) was. In the end [code="sql"]MAX(x) OVER (PARTITION BY y)[/code] should return the same as  [code="sql"]FIRST_VALUE(X) OVER (PARTITION BY Y, ORDER BY X DESC)[/code]But obviously, the MAX / MIN Aggregate Window Functions do not allow you to order your partition by a different column before applying the aggregate. (And it actually does not really make sense to impose a different order on MAX or MIN.)So the whole point of FIRST_VALUE and LAST_VALUE seem to be:[code="sql"]FIRST_VALUE(X) OVER (PARTITION BY Y, ORDER BY [b]SomeOtherColumn[/b] DESC)[/code]Any other points I may have missed?</description><pubDate>Thu, 19 Jan 2012 06:01:54 GMT</pubDate><dc:creator>Christian Buettner-167247</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>I finally see SQL Server catching up, I am so used to of Lead/Lag in DB2. It will make my life little easier. Thanks</description><pubDate>Thu, 19 Jan 2012 05:53:14 GMT</pubDate><dc:creator>ETL_Guy</dc:creator></item><item><title>RE: The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Finally they [b]will[/b] have what Oracle [b]had[/b] delivered ages ago....</description><pubDate>Thu, 19 Jan 2012 02:39:30 GMT</pubDate><dc:creator>Zeev Kazhdan</dc:creator></item><item><title>The new Analytic functions in SQL Server 2012</title><link>http://www.sqlservercentral.com/Forums/Topic1238434-1273-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/articles/SQL+Server+2012/76704/"&gt;The new Analytic functions in SQL Server 2012&lt;/A&gt;[/B]</description><pubDate>Wed, 18 Jan 2012 22:08:15 GMT</pubDate><dc:creator>WayneS</dc:creator></item></channel></rss>