If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > Need help retrieving highest paired value

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-12-12, 17:20
tech_wiz2008 tech_wiz2008 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
Need help retrieving highest paired value

I am attempting to create a report that will display all the yearly, and monthly gas production for a company but the issue I am encountering is finding amended records for a lease. Below is what the query produces:

Company Number Year Month Gas Production Lease Number
3125 2009 1 296 9105701
3125 2009 1 345 165207
3125 2009 1 565 2250593 <--
3125 2009 1 1161 2250593

I would like to omit the lower production gas production, and keep the higher production from the same lease.
Reply With Quote
  #2 (permalink)  
Old 01-12-12, 17:29
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #3 (permalink)  
Old 01-12-12, 17:39
tech_wiz2008 tech_wiz2008 is offline
Registered User
 
Join Date: Jan 2012
Posts: 7
This is the original code:

select distinct [CODING-MAST-OP-NUMBER], YEAR, MONTH, [GAS-WELL-GAS PRODUCTION], RRCID
from Gas_Prod2009a
where [CODING-MAST-OP-NUMBER] = 3125
Order by MONTH asc, [GAS-WELL-GAS PRODUCTION] asc


Will this code work, cause it isn't working for me:

select MAX (ALL | distinct) [CODING-MAST-OP-NUMBER], YEAR, MONTH, [GAS-WELL-GAS PRODUCTION], RRCID
from Gas_Prod2009a
where [CODING-MAST-OP-NUMBER] = 3125
Order by MONTH asc, [GAS-WELL-GAS PRODUCTION] asc
Reply With Quote
  #4 (permalink)  
Old 01-12-12, 23:15
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,609
Try:
Code:
SELECT [CODING-MAST-OP-NUMBER], [YEAR], [MONTH]
,  Max([GAS-WELL-GAS PRODUCTION]) AS [GAS-WELL-GAS PRODUCTION], RRCID
   FROM Gas_Prod2009a
   WHERE [CODING-MAST-OP-NUMBER] = 3125
   GROUP BY [CODING-MAST-OP-NUMBER], [YEAR], [MONTH], RRCID
   ORDER BY [MONTH], [GAS-WELL-GAS PRODUCTION]
-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On