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 ?
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
DEMO
Results