I want to return a table that consists of one column that contains only distinct projectid
, a second column that displays the max(date)
from within the given date-range and a third column that shows additional information. I'm still really new to sql.
Query:
select distinct (a.projectid), versiondate, newvalue
from a
inner join b on a.projectid = b.projectid
where b.contractor = 'SQA Contractor Company-1'
and a.attributename = 'Status'
and versiondate between '2014-10-01 00:00:00' and '2014-10-01 23:59:59'
group by a.projectid, versiondate, newvalue
order by versiondate
What it's returning:
projectid | versiondate | newvalue
-----------+------------------------+--------------------
p27641 | 2014 10 01 12:23:18 | In work
p27641 | 2014 10 01 12:23:21 | In billing
p27641 | 2014 10 01 12:23:45 | completed
p19397 | 2014 10 01 12:25:03 | pending review
p19397 | 2014 10 01 12:25:42 | pending assignment
p10397 | 2014-10-01 12:26:18 | pending-acceptance
What I want it to return:
only the distinct projectid's that represent the most recent versiondate
. I need to see what the newvalue
was on the most recent date for each distinct projectid
.
Trying to put that into words was kind of tough so hopefully I explained my question well. Any help/criticism is accepted.