Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 How to handle cross row computation with SQL?

Author  Topic 

datakeyword
Starting Member

10 Posts

Posted - 2013-07-15 : 21:53:17
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

52326 Posts

Posted - 2013-07-16 : 00:58:46
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
   

- Advertisement -