ROW_NUMBER() OVER (PARTITION BY) 给出相同的行号
ROW_NUMBER() OVER (PARTITION BY) gives same row numbers
我在项目中使用 SAP HANA 数据库。我试过这个 SQL 查询来获取带有行号的值。但它给出了所有行的 1。
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")
这是我得到的结果。
为什么所有行号都变成了1,请问如何解决?
谢谢。
使用这个:ROW_NUMBER() OVER(ORDER BY code)
它是连续序列,你使用 partition by
它会重置每个代码。
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")
我在项目中使用 SAP HANA 数据库。我试过这个 SQL 查询来获取带有行号的值。但它给出了所有行的 1。
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")
这是我得到的结果。
为什么所有行号都变成了1,请问如何解决?
谢谢。
使用这个:ROW_NUMBER() OVER(ORDER BY code)
它是连续序列,你使用 partition by
它会重置每个代码。
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")