combine ROW_NUMBER and COUNT(*) OVER Partition

  • Hello

    Is it some way to combine COUNT(*) and ROW_NUMBER on the same partition ?

    For now I'm using a query like this

    WITH Glob AS (SELECT p.ITEMID,

    p.AffiliateID,

    ROW_NUMBER() OVER(PARTITION BY p.itemid ORDER BY p.processingdate) AS rk,

    COUNT(*) OVER(PARTITION BY p.itemid ) AS qty

    FROM ItemProcessing p

    )

    SELECT

    Itemid,

    AffiliateID,

    Qty

    from Glob where rk=1

    But I can imagine that it will be more efficient to use the same partition to get both rk and Qty ?

    Is there a more effective way

  • SQL Server's implementation of the window functions does not allow for sharing window specification (over clause specs) between functions.

    😎

Viewing 2 posts - 1 through 2 (of 2 total)

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