Click here to Skip to main content
15,920,005 members
Home / Discussions / Database
   

Database

 
AnswerRe: trouble in connecting to Postgre SQL from web server. Pin
Luc Pattyn22-Feb-12 2:56
sitebuilderLuc Pattyn22-Feb-12 2:56 
GeneralRe: trouble in connecting to Postgre SQL from web server. Pin
hellono122-Feb-12 4:06
hellono122-Feb-12 4:06 
Questiondesign a database Pin
messages19-Feb-12 5:06
messages19-Feb-12 5:06 
AnswerRe: design a database Pin
Eddy Vluggen19-Feb-12 5:39
professionalEddy Vluggen19-Feb-12 5:39 
GeneralRe: design a database Pin
Hamid_RT19-Feb-12 5:53
Hamid_RT19-Feb-12 5:53 
AnswerRe: design a database Pin
Eddy Vluggen19-Feb-12 6:09
professionalEddy Vluggen19-Feb-12 6:09 
AnswerRe: design a database Pin
Luc Pattyn19-Feb-12 6:55
sitebuilderLuc Pattyn19-Feb-12 6:55 
GeneralRe: design a database Pin
messages19-Feb-12 17:22
messages19-Feb-12 17:22 
AnswerRe: design a database Pin
Mycroft Holmes19-Feb-12 12:08
professionalMycroft Holmes19-Feb-12 12:08 
GeneralRe: design a database Pin
messages19-Feb-12 17:21
messages19-Feb-12 17:21 
GeneralRe: design a database Pin
Mycroft Holmes19-Feb-12 17:27
professionalMycroft Holmes19-Feb-12 17:27 
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 

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.