Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12345»»»

LEAD - 1 Expand / Collapse
Author
Message
Posted Monday, October 29, 2012 9:39 PM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Thursday, November 6, 2014 1:00 PM
Points: 5,333, Visits: 25,277
Comments posted to this topic are about the item LEAD - 1

If everything seems to be going well, you have obviously overlooked something.

Ron

Please help us, help you -before posting a question please read

Before posting a performance problem please read
Post #1378552
Posted Monday, October 29, 2012 10:18 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, October 16, 2014 10:02 AM
Points: 1,372, Visits: 1,566
Hey Ron, There seems to be some confustion with answer choices here. When we have ORDER BY caluse on Sales, it will order the results in the following fashion:

UserId      UserName Sales
----------- -------- ---------------------------------------
6 Easy 50.00
1 Joe 100.00
3 Charlie 400.00
2 Baker 700.00
4 Able 800.00
5 XRay 1000.00


Now when we apply LEAD function over this, XRay will have NULL value not EASY as mentioned in the ansewer choices.

Please verify!



~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1378561
Posted Monday, October 29, 2012 11:43 PM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, August 28, 2014 8:53 PM
Points: 1,388, Visits: 3,039
Thanks for the intro to a new SQL 2012 function (Making me itch for our app to move on from 2005!). I love the idea of this new function -- much simpler than isolating a Row_Number() in a CTE or doing self-joins.

As Lokesh implies, there may have been some ambiguity in the way this was constructed, or maybe just a disconnect between the SQL code and the stated question. I got my answer by researching BOL on the web (had to -- see above), but assumed that where the question said "sales goal", it meant the LEAD result given an alias "sales" in the SQL. I tlooks as though the LEAD function is ordered by the Sales column in the temp table, whereas the results are ordered by the alias "Sales" assigned to the output of LEAD. My responses were scored as "correct", so now I'm wondering what really happens.

Lokesh, did you run the code with the LEAD function?
Ron, can you confirm?
Post #1378572
Posted Tuesday, October 30, 2012 12:01 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, October 16, 2014 10:02 AM
Points: 1,372, Visits: 1,566
Hi John,

Here is the output what I am getting:

  USERID   USERNAME    SALES  
------------------------------
5 XRay NULL
6 Easy 100
1 Joe 400
3 Charlie 700
2 Baker 800
4 Able 1000


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1378575
Posted Tuesday, October 30, 2012 12:23 AM
Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Friday, May 9, 2014 12:47 AM
Points: 3,448, Visits: 4,407
Thanks for question about the new feature of MSSQL 2012!
Lokesh Vij (10/29/2012)
Hey Ron, There seems to be some confustion with answer choices here. When we have ORDER BY caluse on Sales, it will order the results in the following fashion:

UserId      UserName Sales
----------- -------- ---------------------------------------
6 Easy 50.00
1 Joe 100.00
3 Charlie 400.00
2 Baker 700.00
4 Able 800.00
5 XRay 1000.00


Now when we apply LEAD function over this, XRay will have NULL value not EASY as mentioned in the ansewer choices.

Please verify!


The "Sales value for User Easy" mentioned in the first two options means "the result of the query SELECT Sales FROM #Users1 WHERE UserName = 'Easy' ". Therefore, the "Sales value for User Easy" is equal to 50.00.
Below is the result of the QOTD query:
UserId      UserName SalesGoal
----------- -------- ---------------------------------------
6 Easy 100.00
1 Joe 400.00
3 Charlie 700.00
2 Baker 800.00
4 Able 1000.00
5 XRay NULL

The value 50.00 does not appear in the results, so I see no problem with the answer given.

The only confusion has been pointed out by john.arnott. The alias of the "LEAD (Sales,1) OVER (ORDER BY Sales)" should have been "SalesGoal", not "Sales".
Post #1378580
Posted Tuesday, October 30, 2012 12:31 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, October 16, 2014 10:02 AM
Points: 1,372, Visits: 1,566
vk-kirov (10/30/2012)
Thanks for question about the new feature of MSSQL 2012!
Lokesh Vij (10/29/2012)
Hey Ron, There seems to be some confustion with answer choices here. When we have ORDER BY caluse on Sales, it will order the results in the following fashion:

UserId      UserName Sales
----------- -------- ---------------------------------------
6 Easy 50.00
1 Joe 100.00
3 Charlie 400.00
2 Baker 700.00
4 Able 800.00
5 XRay 1000.00


Now when we apply LEAD function over this, XRay will have NULL value not EASY as mentioned in the ansewer choices.

Please verify!


The "Sales value for User Easy" mentioned in the first two options means "the result of the query SELECT Sales FROM #Users1 WHERE UserName = 'Easy' ". Therefore, the "Sales value for User Easy" is equal to 50.00.
Below is the result of the QOTD query:
UserId      UserName SalesGoal
----------- -------- ---------------------------------------
6 Easy 100.00
1 Joe 400.00
3 Charlie 700.00
2 Baker 800.00
4 Able 1000.00
5 XRay NULL

The value 50.00 does not appear in the results, so I see no problem with the answer given.

The only confusion has been pointed out by john.arnott. The alias of the "LEAD (Sales,1) OVER (ORDER BY Sales)" should have been "SalesGoal", not "Sales".


May be I am interpretting it wrongly, "the sales value for user EASY does not appear in the result" --> I thougt this means "sales value corresponding to user EASY should be NULL", which indeed is not the case


~ Lokesh Vij

Guidelines for quicker answers on T-SQL question
Guidelines for answers on Performance questions

Link to my Blog Post --> www.SQLPathy.com

Follow me @Twitter

Post #1378582
Posted Tuesday, October 30, 2012 1:01 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Thursday, July 31, 2014 7:15 PM
Points: 1,129, Visits: 1,163
oh , I got it wrong , I thought instead of null, it will give default 0 as output..
..
learned something though
thanks for the question...


~ demonfox
___________________________________________________________________
Wondering what I would do next , when I am done with this one
Post #1378587
Posted Tuesday, October 30, 2012 1:26 AM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 6:20 AM
Points: 4,104, Visits: 5,462
Really interesting question, thanks Ron
Some really interesting new functionality that comes with SQL2012.


____________________________________________
Space, the final frontier? not any more...
All limits henceforth are self-imposed.
“libera tute vulgaris ex”
Post #1378590
Posted Tuesday, October 30, 2012 1:31 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:46 AM
Points: 13,528, Visits: 11,324
Great question! Always good to have some 2012 questions.

For people who want to learn more about the subject, this is an amazing book:

http://www.amazon.com/Microsoft-Server-High-Performance-Window-Functions/dp/0735658366/ref=cm_rdp_product




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1378595
Posted Tuesday, October 30, 2012 1:49 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Yesterday @ 7:51 PM
Points: 17,948, Visits: 15,947
Thanks Ron.



Jason AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server, MVP


SQL RNNR

Posting Performance Based Questions - Gail Shaw
Post #1378599
« Prev Topic | Next Topic »

Add to briefcase 12345»»»

Permissions Expand / Collapse