Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Is there a way to select a max row for each group in SQL ( with distinct code )

$
0
0

Dear friends, 

My table is as show in below…  for each ‘grpid’ I want get row with Max tiv value and code should be distinct. Ie in result, code & grpid will come only once.

grpid

code

Tiv

2

GB

9

2

IN

7

1

GB

11

1

US

10

Result:    ( we are selecting   IN even though for grpid 2 ‘GB’ has max value)

grpid

code

Tiv

2

IN

7

1

GB

11


-Sajid


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>