需要在Oracle PLSQL中获得适当/预期的行号
当我使用以下查询
SELECT P.RefNum
,Ian.ID
,Ian.Date
,Igl.Name
,Ian.Comments
,ROW_NUMBER() OVER (
PARTITION BY P.RefNum
,I.Name ORDER BY Ian.Name
) AS ROWNUMBER
FROM Table1 P
INNER JOIN Table2 Igl ON P.GrpNum = Igl.GrpNum
INNER JOIN Table3 I ON Igl.Num = I.Num
INNER JOIN Table4 Ian ON Igl.Num = Ian.Num
WHERE P.RefNum = <InputParameter>
但预期的输出应如下(请参阅 rownumber 列)
Getting the following output when i use the below query
SELECT P.RefNum
,Ian.ID
,Ian.Date
,Igl.Name
,Ian.Comments
,ROW_NUMBER() OVER (
PARTITION BY P.RefNum
,I.Name ORDER BY Ian.Name
) AS ROWNUMBER
FROM Table1 P
INNER JOIN Table2 Igl ON P.GrpNum = Igl.GrpNum
INNER JOIN Table3 I ON Igl.Num = I.Num
INNER JOIN Table4 Ian ON Igl.Num = Ian.Num
WHERE P.RefNum = <InputParameter>
But the expected output should be as below (Refer RowNumber column)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先找到“组”这些行属于(由refnum和name划分)(这就是
temp
cte所做的),然后应用dense_rank来获取最终结果。示例数据(简化,因为我没有您的表):
查询从这里开始:
First find "groups" each of those rows belongs to (partitioned by refnum and name) (that's what the
temp
CTE does), and then apply dense_rank to fetch the final result.Sample data (simplified, as I don't have your tables):
Query begins here: