Select only the rows with MAX(date)

时间:2019-05-31 11:27:35

标签: sql-server-2008

I want to make a query that returns Project, date and Completed, but only shows one row per project based on the latest date. So currently my view is showing two rows for Project 053622-011...

Project         Date            Completed
053622-010  2018-04-18  Yes
053622-011  2019-03-26  No
053622-011  2019-04-01  Yes

I would like only the following to show...

Project         Date            Completed
053622-010  2018-04-18  Yes
053622-011  2019-04-01  Yes

Any help with this would be greatly appreciated! :)

This is what I have tried so far...

SELECT

       [Suffix_code] as 'Project'
       ,MAX([Sent_date]) as 'Date'
      ,[Complete_WP_flag] as 'Completed'

  FROM [CM_PROJECT_INFO_MASTER]

  GROUP BY
  [Suffix_code],
  [Complete_WP_flag]

0 个答案:

没有答案