计算属于一起的行 [英] Count rows belonging together

查看:36
本文介绍了计算属于一起的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个程序来填充更高运费的折扣值.

I have to create a Procedure filling in discount values on higher shipping amounts.

在我的表格中,有所有商品编号、折扣所需的订单数量和折扣.

In my Table there are all article numbers, the amount of orders needed for the discount and the discount.

我想在我的更新中包含 CASE WHEN 所需的商品编号 + 所需订单数量的计数值.

I want to have the article number + a counting value of the amount of orders needed just for the CASE WHEN in my update.

现在我只得到完整选择的行号:

Right now I only get the rownumber of the complete select:

IB-000074   53
IB-000074   8487
IB-000074   8592
IB-000075   8593
IB-000075   54
IB-000075   8486

我需要显示如下内容:

IB-000074   1
IB-000074   2
IB-000074   3
IB-000075   1
IB-000075   2
IB-000075   3

有谁知道如何用 1 替换最低值,用 2 替换第二低值,依此类推?

Anyone knows how to replace the lowest value with 1, the 2nd lowest with 2 and so on?

推荐答案

参考链接:Row_number()

参考链接:Over 子句

你可以使用

row_number()over(partition by ID order by something)

参考链接:示例

这篇关于计算属于一起的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆