advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Sports statistics are an obvious application for ranking functions and "Top-N." What other applications are there for numbered ranking, as opposed to simply sorting the results? Do you have tricky calculation these techniques might solve, but you're not sure how? Tell us in database.db2.general.
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.8/5 | Rate this item | 10 users have rated this item.
 

Mastering Top-N and OLAP Queries in DB2

DB2 Pro Greg Nash teaches you to use DB2's OLAP functions to refine the data, then use FETCH FIRST to minimize the results.  


advertisement
ith the help of today's Web integration and GUI tools, it's now much easier to build reports without any programming. SQL provides GROUP BY and ORDER BY clauses, to collate and sort otherwise unordered data. But sometimes we want more flexibility. Consider the following report requests:
  • List my top two clients, according to sales totals
  • List the next three clients
  • Rank all clients by sales volume, but list them alphabetically
  • Rank all clients by sales volume on a per-month basis
  • Show each client's year-to-date and all-time cumulative totals
  • A rolling three-month average, from one before to one after, and the same from the previous year
Traditionally the extra processing for these kinds of queries was done in application code. Using newer SQL constructs, we can move the processing closer to the data itself, both for efficient processing and simpler data access.




How can I rank my results in DB2 and retrieve only the data I want?



Use DB2's OLAP functions to refine the data; Use FETCH FIRST to minimize the results.
  Next Page: FETCH FIRST for Top-N


Page 1: IntroductionPage 4: Partitioning—Ranking within Groups
Page 2: FETCH FIRST for Top-NPage 5: A Wider RANGE of Functions
Page 3: Ranking and Numbering 
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs