Click here to Skip to main content
15,890,185 members
Home / Discussions / Database
   

Database

 
GeneralRe: design a database Pin
messages19-Feb-12 19:40
messages19-Feb-12 19:40 
GeneralRe: design a database Pin
Mycroft Holmes19-Feb-12 20:03
professionalMycroft Holmes19-Feb-12 20:03 
GeneralRe: design a database Pin
messages20-Feb-12 0:54
messages20-Feb-12 0:54 
GeneralRe: design a database Pin
Jörgen Andersson20-Feb-12 3:02
professionalJörgen Andersson20-Feb-12 3:02 
GeneralRe: design a database Pin
messages20-Feb-12 3:20
messages20-Feb-12 3:20 
GeneralRe: design a database Pin
Jörgen Andersson20-Feb-12 3:34
professionalJörgen Andersson20-Feb-12 3:34 
AnswerRe: design a database Pin
smcnulty20005-Mar-12 22:03
smcnulty20005-Mar-12 22:03 
QuestionFinding the Max value per group. Pin
Clark Kent12317-Feb-12 5:47
professionalClark Kent12317-Feb-12 5:47 
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..
HTML
<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?
SQL
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. Pin
scottgp17-Feb-12 8:19
professionalscottgp17-Feb-12 8:19 
GeneralRe: Finding the Max value per group. Pin
Corporal Agarn17-Feb-12 8:36
professionalCorporal Agarn17-Feb-12 8:36 
GeneralRe: Finding the Max value per group. Pin
Clark Kent12321-Feb-12 2:58
professionalClark Kent12321-Feb-12 2:58 
AnswerRe: Finding the Max value per group. Pin
Eddy Vluggen17-Feb-12 8:47
professionalEddy Vluggen17-Feb-12 8:47 
QuestionRe: Finding the Max value per group. Pin
Clark Kent12321-Feb-12 2:55
professionalClark Kent12321-Feb-12 2:55 
AnswerRe: Finding the Max value per group. Pin
Eddy Vluggen21-Feb-12 7:35
professionalEddy Vluggen21-Feb-12 7:35 
GeneralRe: Finding the Max value per group. Pin
Clark Kent12322-Feb-12 2:21
professionalClark Kent12322-Feb-12 2:21 
GeneralRe: Finding the Max value per group. Pin
Eddy Vluggen23-Feb-12 0:05
professionalEddy Vluggen23-Feb-12 0:05 
QuestionSSRS 2005 verses OUTLOOK 2007 Pin
SQL Ed17-Feb-12 1:00
SQL Ed17-Feb-12 1:00 
AnswerRe: SSRS 2005 verses OUTLOOK 2007 Pin
cjb1105-Apr-12 1:24
cjb1105-Apr-12 1:24 
Questionoracle 11g alias to query Pin
hadad14-Feb-12 22:28
hadad14-Feb-12 22:28 
AnswerRe: oracle 11g alias to query Pin
Jörgen Andersson15-Feb-12 1:37
professionalJörgen Andersson15-Feb-12 1:37 
AnswerRe: oracle 11g alias to query Pin
Chris Meech15-Feb-12 3:00
Chris Meech15-Feb-12 3:00 
AnswerRe: oracle 11g alias to query PinPopular
David Skelly15-Feb-12 6:24
David Skelly15-Feb-12 6:24 
JokeRe: oracle 11g alias to query Pin
Bernhard Hiller15-Feb-12 21:04
Bernhard Hiller15-Feb-12 21:04 
GeneralRe: oracle 11g alias to query Pin
David Skelly15-Feb-12 22:05
David Skelly15-Feb-12 22:05 
Questionconcept of database Pin
messages13-Feb-12 22:56
messages13-Feb-12 22:56 

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

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