May 3, 2016 at 3:16 pm
I want to get values based on highest and second highest max dates...
I am wondering if I could join the same source table twice with next table?
This is how I am getting for highest one.... Can someone advice How I should go about for second highest in the same query ?
I am doing
Select MaxDate , B. TotalMaxValues from ( Select Max(maxDate)Maxdate from CTE1)A
Left Outer Join B on A.Maxdate = B.Date
May 3, 2016 at 3:30 pm
Guess I figured out.. An inner join helped
May 3, 2016 at 3:38 pm
Not enough information to help or validate, sorry.
May 3, 2016 at 8:04 pm
I guess I must not understand the question either. From the way I read it, I would do something like this:
SELECT TOP 2 DateColumn
FROM dbo.TableName
ORDER BY DateColumn;
May 4, 2016 at 8:31 am
Ed Wagner (5/3/2016)
I guess I must not understand the question either. From the way I read it, I would do something like this:
SELECT TOP 2 DateColumn
FROM dbo.TableName
ORDER BY DateColumn;
You need a descending order here if you want the two highest dates.
Drew
J. Drew Allen
Business Intelligence Analyst
Philadelphia, PA
May 4, 2016 at 8:36 am
drew.allen (5/4/2016)
Ed Wagner (5/3/2016)
I guess I must not understand the question either. From the way I read it, I would do something like this:
SELECT TOP 2 DateColumn
FROM dbo.TableName
ORDER BY DateColumn;
You need a descending order here if you want the two highest dates.
Drew
DOH! Thanks, Drew.
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply