Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ROW_NUMBER() OVER (PARTITION BY) gives same row numbers

I use SAP HANA database for a project. I tried this SQL query to get values with a row number. But it gives 1 as all rows.

    SELECT ROW_NUMBER() OVER (PARTITION BY "ItemCode") AS "ID", "ItemCode", "CommitedQty", "JobId", "WarehouseID"
    FROM
        (SELECT "ItemCode", SUM("CommitedQty") AS "CommitedQty","JobId", "WarehouseID"
        FROM "Stock" 
        WHERE "BaseEntry" = 10352
        GROUP BY "ItemCode","JobId", "WarehouseID")

This is the result that I get.

Result

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Why all row numbers are became 1. How do I solve this issue?

Thank you.

>Solution :

use this :

SELECT ROW_NUMBER() OVER (ORDER BY "ItemCode") AS "ID", "ItemCode", "CommitedQty", "JobId", "WarehouseID"
    FROM
        (SELECT "ItemCode", SUM("CommitedQty") AS "CommitedQty","JobId", "WarehouseID"
        FROM "Stock" 
        WHERE "BaseEntry" = 10352
        GROUP BY "ItemCode","JobId", "WarehouseID")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading