Click here to Skip to main content
15,892,072 members
Home / Discussions / Database
   

Database

 
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 
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 
Can you extend the sample population to give some more detail?

In the meantime, here's something to play with;
SQL
SET NOCOUNT ON;
BEGIN TRANSACTION

IF OBJECT_ID('vPSR') IS NOT NULL DROP TABLE vPSR

SELECT 1000700 as ProjectID, 
       05 as ReportMonth,
       2008 as ReportYear
  INTO vPSR
UNION SELECT 1000700, 06, 2008
UNION SELECT 1000700, 07, 2008
UNION SELECT 1000700, 12, 2008
UNION SELECT 1000700, 01, 2009
UNION SELECT 1000701, 11, 2011
UNION SELECT 1000701, 12, 2009

-- If you insist on using a max
SELECT TOP 1 *
  FROM vPSR
 WHERE ReportYear = (SELECT MAX(ReportYear) FROM vPSR)
 ORDER BY ReportMonth DESC

-- this would do too;
SELECT TOP 1 *
  FROM vPSR
 ORDER BY ReportYear DESC, ReportMonth DESC

-- per project?
SELECT DISTINCT ProjectID
     , (SELECT MAX(ReportYear) FROM vPSR WHERE ProjectID = A.ProjectID)
     , (SELECT TOP 1 ReportMonth FROM vPSR WHERE ProjectID = A.ProjectID AND ReportYear = (
			SELECT MAX(ReportYear) FROM vPSR WHERE ProjectID = A.ProjectID) ORDER BY ReportMonth DESC)
  FROM vPSR A

ROLLBACK

My results;
txt
ProjectID   ReportMonth ReportYear
----------- ----------- -----------
1000701     11          2011

ProjectID   ReportMonth ReportYear
----------- ----------- -----------
1000701     11          2011

ProjectID               
----------- ----------- -----------
1000700     2009        1
1000701     2011        11

Bastard Programmer from Hell Suspicious | :suss:

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 
AnswerRe: concept of database Pin
Simon_Whale14-Feb-12 0:16
Simon_Whale14-Feb-12 0:16 
AnswerRe: concept of database Pin
uspatel17-Feb-12 23:54
professionaluspatel17-Feb-12 23:54 
NewsRe: concept of database Pin
Eddy Vluggen18-Feb-12 2:52
professionalEddy Vluggen18-Feb-12 2:52 
GeneralRe: concept of database Pin
messages19-Feb-12 5:09
messages19-Feb-12 5:09 

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.