I have this query select max(maxseq) as maxseq, cos, clm, org_id, typ From test group by cos, clm, org_id, typthat produces this tableMaxNum COS CLM Org_id Typ2 209590 209590 029 R3 209590 209590 029 T1 209590 209590 219 T4 209590 209590 PC2 R5 209590 209590 PC2 T
What I want is this:I want to get this result:MaxNum Cos CLM org_id Type5 209590 209590 PC2 THow do I get just the maxnum to show up which is 5? I tried this query and get the same resultsSELECT cos, clm, org_id, typ,maxseqFROM(select cos, clm, org_id, typ, maxseq, row_number() over(partition by cos, clm, org_id, typ order by maxseq desc) as rown From test) t1WHERE rown = 1 ORDER BY maxseqWhat am I missing?
here's the table info:CREATE TABLE [dbo].[test]([MaxSeq] [smallint] NOT NULL,[COS] [char](6) NOT NULL, [CLM] [char](6) NOT NULL, [ORG_ID] [varchar](4) NOT NULL, [TYP] [char](1) NOT NULL, [t2jurisid] [int] IDENTITY(1,1) NOT NULL)Insert into testSelect '2', '209590', '209590', '029', 'R' union allSelect '3', '209590', '209590', '029', 'T' union allSelect '1', '209590', '209590', '219', 'T' union allSelect '4', '209590', '209590', 'PC2', 'R' union allSelect '5', '209590', '209590', 'PC2', 'T'