Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7903753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:49:49+00:00 2026-06-03T09:49:49+00:00

i am trying to build a query to compute Which org has the highest

  • 0

i am trying to build a query to compute Which org has the highest officers attendance each month in each district?
Terms:
“District” and “loinum” mean the same thing. There are 31 districts in Massachusetts.
“Org” is a local chapter, which is in one of the Districts.
“Officers” are the positions named “WM” through “TY”.
the table is

loinum month   year  org  wm sw jw  ty
1        8     2011  Ma   0   1  1  1 
1        9     2011  CA   1   1  0  0 
1        8     2011  La   1   0  0  1 
2        7     2011  ME   1   1  1  1
2        6     2011  io   1   0  0  0  
2        9     2011  BO   1   0  0  0 
3        5     2011  Ch   1   1  1  1
3        4     2011  AL   0   0  0  1   
3        4     2011  EG   0   1  1  0

how i can compute and get the max for EACH loinum and EACH month ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:49:50+00:00Added an answer on June 3, 2026 at 9:49 am

    This is a generic solution although for specific DB’s there may be better. Create an inline view that gets the max of the values for each loinum, month, and year. Then join it back to the main table.

    Note: If there’s a tie for max there will be multiple results for a given loinum, month, and year

    SELECT t.* 
    FROM   table1 t 
           INNER JOIN (SELECT loinum, 
                              month, 
                              year, 
                              Max(wm + sw + jw + ty) oCount 
                       FROM   table1 
                       GROUP  BY loinum, 
                                 month, 
                                 year) AS MAX 
             ON t.loinum = max.loinum 
                AND t.month = max.month 
                AND t.year = max.year 
                AND ( wm + sw + jw + ty ) = max.oCount
    

    DEMO

    Results

    LOINUM  MONTH   YEAR    ORG WM  SW  JW  TY
    1           8   2011    Ma  0   1   1   1
    1           9   2011    CA  1   1   0   0
    2           6   2011    io  1   0   0   0
    2           7   2011    ME  1   1   1   1
    2           9   2011    BO  1   0   0   0
    3           4   2011    EG  0   1   1   0
    3           5   2011    Ch  1   1   1   1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a query which will do this: Lets say for
I am trying to build a SQL query using ActiveRecord methods. The query has
I am trying to build a query that displays the rows with the highest
Using JPA 2 with EclipseLink implementation. I'm trying to build a dynamic query which
I'm trying to build a query with hibernate criteria for the following scenario: Two
I am trying to build correct query for my test server, and i am
I am trying to build a query that will select based on a DateTime
I'm trying to build an update query but I keep getting the following error:
I am trying to build a CAML query for SharePoint 2007 environment, to get
Greetings all, I have a question. I am trying to build a parametrized query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.