• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Looking for Number Two

    August 2, 2002 Timothy Prickett Morgan

    Hey, Ted:

    I have a file of sales reps and the amount of sales, in dollars, so far this year. I can easily find the top producer using SQL.

    select repid, amt from sales2 where amt =       
        (select max(amt) from sales2)
    

    How do I find the number-two producer?

    — Roger

    There are probably several ways to answer your question, Roger.

    First, here’s the raw data that I’ll use to illustrate:

    REPID        AMT 
    JLM1      25,922 
    NTP2     177,208 
    LJS2      15,424 
    CRC0     122,730 
    HFH1      95,682 
    JKS0      76,903 
    JLM2      55,088 
    JTL4      99,944 
    MWS0      12,155 
    BRS1      54,673
    

    To find the number two producer:

    select repid, amt from sales2 as a where 1 = 
      (select count(*) from sales2 as b where    
        b.amt > a.amt)                           
    

    For each row (record), the inner select produces the number of reps with a higher sales figure. The number two producer is the one who has only one person with a higher sales figure, thus the number one appears before the equal sign.

    The query returns one row.

    REPID        AMT
    CRC0     122,730
    

    If you wanted to find the third highest producer, you would replace the 1 with a 2.

    select repid, amt from sales2 as a where 2 = 
      (select count(*) from sales2 as b where    
        b.amt > a.amt)                           
    

    Again, the query returns one row.

    REPID        AMT
    JTL4      99,944
    

    If you want to list the top two producers, change the equal sign to a greater-than-or-equal relation.

    select repid, amt from sales2 as a where 1 >=
      (select count(*) from sales2 as b where    
        b.amt > a.amt)                           
    

    The query returns two rows.

    REPID        AMT
    NTP2     177,208
    CRC0     122,730
    

    — Ted

    Sponsored By
    CENTERFIELD TECHNOLOGY

    $10,000 of Consulting for only $925

    Not only do we take the guesswork out of iSeries DASD Management with disk/HUNTER, but Centerfield Technology also offers a robust set of iSeries tools for application performance and user access control and diagnostics.

    Check out our low cost/high value service offering, the SQL Insurance Analysis. For only $925 we will show you how to increase the performance of your business process and how to secure your exposed critical files. Our analysis is geared toward any one using SQL-based applications on the iSeries–J.D Edwards OneWorld® and WorldSoftware®, MAPICS, BPCS, Web Sphere, Data Warehousing, applications developed in-house, etc.

    Key Benefits of SQL Insurance Analysis

    • The SQL Insurance Analysis deliverables are specific to each customer. Since the ‘raw material’ for the analysis comes from data you collect, the conclusions and recommendations are truly actionable.

    • Because we use our tools to do the analysis, we have the flexibility to adjust the SQL Insurance Analysis to focus on a specific part of a customer’s application. This ability to hone in on ‘areas of pain’ provides even more information and value. Individual reports are provided on:
      • Top 3 index recommendations most likely to boost application performance

      • Top resource intensive SQL statements and what to do next

      • Largest (CPU consumption) jobs with specific tuning options

      • Longest running programs by CPU time with tuning options

      • File transaction rates for effective index management

      • Unused Indexes to potentially delete for disk conservation
      • Duplicate indexes to reduce maintenance

      • Select/OMIT indexes that can be optimized

      • Security exposures of critical files

    • The SQL Insurance Analysis reporting process includes a post-assessment Q&A with a CTI analysis specialist, surfacing additional information and expert feedback from our knowledge base and experience with other similar customers.

    This extensive program set combines a methodology and tools to simplify the complex and time-consuming process of controlling and tuning SQL applications. Our easy, low cost analysis will help you fix availability problems now, before significant cost/damage occurs. And, we’ll show you how to control application performance and query access permanently – 24/7! Click here for more information.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags: Tags: mgo_rc, Volume 2, Number 58 -- August 2, 2002

    Sponsored by
    ARCAD Software

    [Webinar] Trends for 2026: ARCAD Software’s strategic vision

    Between the acceleration of artificial intelligence, constant pressure to modernize existing systems, and ever-increasing security requirements, 2026 is shaping up to be a decisive year for legacy platforms.

    At the start of this new year, this webinar offers strategic insight into the future of these critical environments, which are at the heart of information systems.

    Join Philippe Magne, CEO of ARCAD Software, as he shares his analysis of the major trends and structural issues facing organizations:

    • DevSecOps: What are the current trends in DevOps transformation?
    • Generative artificial intelligence: What are the concrete use cases and measurable benefits for application development and maintenance?
    • Critical application security: How to respond to growing and sophisticated threats?
    • Cloud and hybridization: How do legacy applications fit into current cloud strategies?

    Save your seat for March 24 at 11 AM EDT!

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Free Software from Kisco Confirm File Deletions in Qshell

    Leave a Reply Cancel reply

MGO Volume: 2 Issue: 58

This Issue Sponsored By

    Table of Contents

    • Free Software from Kisco
    • Looking for Number Two
    • Confirm File Deletions in Qshell

    Content archive

    • The Four Hundred
    • Four Hundred Stuff
    • Four Hundred Guru

    Recent Posts

    • No Joke: Big Memory And Flash Price Hikes Coming April 1
    • Strategic Topics To Think About For 2026, Part 2
    • Guru: IBM i Job Log Detective Brings Structure To Job Log Analysis In VS Code
    • IBM Launches Hybrid Cloud Backup Product With Cobalt Iron
    • IBM i PTF Guide, Volume 28, Number 10
    • Why You Need To Think About Offsite Data Protection
    • IBM Gets Bob 1.0 Off The Ground
    • You Store The Crown Jewels In A Safe, Not In A Bucket
    • More Power Systems Withdrawals, And Some From Red Hat, Too
    • Price Increases Are Here, Or Pending, And For Sure For Memory

    Subscribe

    To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

    Pages

    • About Us
    • Contact
    • Contributors
    • Four Hundred Monitor
    • IBM i PTF Guide
    • Media Kit
    • Subscribe

    Search

    Copyright © 2025 IT Jungle