Click here to Skip to main content

Database

   

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
GeneralRe: design a database PinmemberMycroft Holmes20:03 19 Feb '12  
GeneralRe: design a database Pinmembermessages0:54 20 Feb '12  
GeneralRe: design a database PinmemberJörgen Andersson3:02 20 Feb '12  
GeneralRe: design a database Pinmembermessages3:20 20 Feb '12  
GeneralRe: design a database PinmemberJörgen Andersson3:34 20 Feb '12  
AnswerRe: design a database Pinmembersmcnulty200022:03 5 Mar '12  
QuestionFinding the Max value per group. PinmemberClark Kent1235:47 17 Feb '12  
I am having such a hard time writing a SQL query. Can someone please look over this query and see where am I going wrong?
 
I will be using the XML elements to describe the table even though I am using SQL Server 2008 R2..
<vPSR>
 <ProjectID/>
 <ReportMonth Comment="2 digit Month. (MM)" />
 <ReportYear Comment="4 digit Year. (YYYY)" />
</vPSR>
 
Here is an example of the data that is listed.
ProjectID ReportMonth ReportYear
1000700 05 2008
1000700 06 2008
1000700 07 2008
1000700 12 2008
1000700 01 2009 <-- I want the query to find this! Even though the Month is not the max value, but the Year is the Max value.
 
Here is what I have so far. Where am I going wrong?
SELECT vPSR.ProjectID, vPSR.ReportMonth, vPSR.ReportYear
    FROM vPSR
    WHERE vPSR.ReportMonth =
        (SELECT MAX(ReportMonth)
            FROM vPSR AS f
            WHERE f.ProjectID = ProjectID
            AND ReportYear =
                (SELECT MAX(ReportYear)
                FROM vPSR AS k
                WHERE k.ProjectID = vPSR.ProjectID))
    ORDER BY vPSR.ProjectID ASC
 
I got the idea on how to write the above query here.[^] I don't understand it that well.
 
If you need me to clarify anything please do not hesitate to ask.
AnswerRe: Finding the Max value per group. Pinmemberscottgp8:19 17 Feb '12  
GeneralRe: Finding the Max value per group. Pinmemberdjj558:36 17 Feb '12  
GeneralRe: Finding the Max value per group. PinmemberClark Kent1232:58 21 Feb '12  
AnswerRe: Finding the Max value per group. PinmemberEddy Vluggen8:47 17 Feb '12  
QuestionRe: Finding the Max value per group. PinmemberClark Kent1232:55 21 Feb '12  
AnswerRe: Finding the Max value per group. PinmemberEddy Vluggen7:35 21 Feb '12  
GeneralRe: Finding the Max value per group. PinmemberClark Kent1232:21 22 Feb '12  
GeneralRe: Finding the Max value per group. PinmemberEddy Vluggen0:05 23 Feb '12  
QuestionSSRS 2005 verses OUTLOOK 2007 PinmemberSQL Ed1:00 17 Feb '12  
AnswerRe: SSRS 2005 verses OUTLOOK 2007 Pinmembercjb1101:24 5 Apr '12  
Questionoracle 11g alias to query [modified] Pinmemberhadad22:28 14 Feb '12  
AnswerRe: oracle 11g alias to query PinmemberJörgen Andersson1:37 15 Feb '12  
AnswerRe: oracle 11g alias to query PinmemberChris Meech3:00 15 Feb '12  
AnswerRe: oracle 11g alias to query PinPopularmemberDavid Skelly6:24 15 Feb '12  
JokeRe: oracle 11g alias to query PinmemberBernhard Hiller21:04 15 Feb '12  
GeneralRe: oracle 11g alias to query PinmemberDavid Skelly22:05 15 Feb '12  
Questionconcept of database Pinmembermessages22:56 13 Feb '12  
AnswerRe: concept of database PinmemberSimon_Whale0:16 14 Feb '12  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Beta | 2.5.120517.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid