Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

select last record in group

Below is the code I am using to select the records from the attached table.

I need the last [chgid] ROW ONLY so the results would like the second sample in the attachment.

select clcharge.CHGID
, company
, ssno
, account
, procdesc
from CLCHARGE
where clcharge.COMPANY = 'rmr' and clcharge.ENTRYDATE = '2012-09-20 00:00:00.000'
group by CHGID, COMPANY, SSNO, ACCOUNT, PROCDESC
record-sample.xlsx
0
Danean
Asked:
Danean
1 Solution
 
BrainfebCommented:
Try This,


Select * from
(select clcharge.CHGID
, company
, ssno
, account
, procdesc,ROW_NUMBER() Over(Partition By SSNO order by CHGID desc) As RowNum

from CLCHARGE
where clcharge.COMPANY = 'rmr' and clcharge.ENTRYDATE = '2012-09-20 00:00:00.000'
group by CHGID, COMPANY, SSNO, ACCOUNT, PROCDESC )A
where A.RowNum = 1
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now