• 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] Synchronous IBM i and non-IBM i Deployments
    April 13 at 12 p.m. ET

    Do you need to automate and synchronize deployments across ALL your environments and applications?

    Many backend IBM i applications have off-platform components, such as an API layer, or Web front-end. To ensure your application stays reliable, artifacts must be deployed securely and in-sync.

    In our Webinar, learn how to orchestrate all your deployments, multi-platform and multi-cloud, using DROPS by ARCAD Software:

    – One single console to deploy across multiple endpoints – IBM i, Windows, Linux, IBM z, on prem or cloud

    – Real-time visibility of application status, from anywhere

    – Deployment plans and one-click-deploy

    – Rollback on error

    Simplify and secure your application delivery.

    Register Now

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Changing Languages on a 5250 Screen Valuable Newsletters

    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

    • IBM Tweaks Some Power Systems Prices Down, Others Up
    • Disaster Recovery: From OS/400 V5R3 To IBM i 7.4 In 36 Hours
    • The Disconnect In Modernization Planning And Execution
    • Superior Support: One Of The Reasons You Pay The Power Systems Premium
    • IBM i PTF Guide, Volume 25, Number 13
    • IBM i Has a Future ‘If Kept Up To Date,’ IDC Says
    • When You Need Us, We Are Ready To Do Grunt Work
    • Generative AI: Coming to an ERP Near You
    • Four Hundred Monitor, March 22
    • IBM i PTF Guide, Volume 25, Number 12

    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 © 2023 IT Jungle