SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Development Tools
 Other Development Tools
 How to handle cross row computation with SQL?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

datakeyword
Starting Member

10 Posts

Posted - 07/15/2013 :  21:53:17  Show Profile  Reply with Quote
In Java application development, ordered or cross-row computation based on database is oftenly involved, such as the last three, the previous one of the current record, the top five, the last but one, and the ranking of a certain record.

For instance,to find out the monthly growth rate of contract values for each sales man in 2012 in a Contract table. We need to firstly group by salesman, group by year within each group, group by month for each year and summarize, and lastly, perform the inter-row computation between the current month and its previous month.

With esProc script, it can be written as bellow:



And what do you think of such solution?
Are there any better ways to deal with it with SQL or Oracle?

Jim King
BI technology consultant for Raqsoft
10 + years of experience on BI/OLAP application, statistical computing and analytics
Email: Contact@raqsoft.com
Website: www.raqsoft.com
Blog: datakeyword.blogspot.com/

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 07/16/2013 :  00:58:46  Show Profile  Reply with Quote
In SQL Server, you can make use of window functions like ROW_NUMBER() for this. You just need to create a temporary table/CTE to generate and use it for comparison.

http://msdn.microsoft.com/en-us/library/ms186734.aspx

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000