2

I have the table named DealOffers :

input table

I want to select only one record from each group of dealIds where Price is minimum.

i.e : the expected output should be like this:

enter image description here

Bimal Das
  • 1,882
  • 5
  • 28
  • 53

1 Answers1

2

You can do something like this. However, you should consider performance if you end up having to do this on a massive scale.

select *
from (
    select *,
        SeqNum = row_number() over(
            partition by DealId
            order by Price)
    from DealOffers) do
where do.SeqNum = 1;
square_particle
  • 526
  • 2
  • 7