Query Performance

  • This should do the trick for you:

    DECLARE @Test TABLE (

    VK int,

    PK int,

    FK int,

    Amt int

    )

    INSERT INTO @Test

    SELECT 3, 130, 129, 100 UNION ALL

    SELECT 3, 130, 130, 100 UNION ALL

    SELECT 3, 130, 131, 100 UNION ALL

    SELECT 4, 130, 129, 10 UNION ALL

    SELECT 4, 130, 130, 10

    ;WITH RankedTest AS (

    SELECT *, RN = ROW_NUMBER() OVER(PARTITION BY PK, FK ORDER BY VK DESC)

    FROM @Test AS A

    )

    SELECT *

    FROM RankedTest

    WHERE RN = 1

    Hope this helps

    Gianluca

    -- Gianluca Sartori

Viewing post 1 (of 2 total)

You must be logged in to reply to this topic. Login to reply