计算列中的行重复值 sql

count row duplicate values in a column sql

我需要查询以获得以下结果。目的是统计articlecode中某一列的重复值。重复的行也应该被截断或显示。

Table_1:(使用查询前)

processname         articlecode     articlename    stock    createdon
STITCHING PRODUCT   TH11592-9192    M/C EMB TOP PCS 2000    8/16/2021
STITCHING PRODUCT   TH11592-9192    M/C EMB TOP PCS 6200    8/23/2021
STITCHING PRODUCT   TH11592-9192    M/C EMB TOP PCS 4450    8/24/2021
STITCHING PRODUCT   TH11592-9193    BACK CUT PCS    4000    8/14/2021
STITCHING PRODUCT   TH11592-9193    BACK CUT PCS    6200    8/23/2021
STITCHING PRODUCT   TH11592-9259    LINNING CUT PCS 4000    8/14/2021
STITCHING PRODUCT   TH11592-9259    LINNING CUT PCS 2000    8/16/2021
STITCHING PRODUCT   TH11592-9259    LINNING CUT PCS 6200    8/23/2021

Table_1:(使用查询后,table应该如下所示)

processname         articlecode     articlename     stock   createdon   rown
STITCHING PRODUCT   TH11592-9192    M/C EMB TOP PCS 2000    8/16/2021   1
STITCHING PRODUCT   TH11592-9192    M/C EMB TOP PCS 6200    8/23/2021   1
STITCHING PRODUCT   TH11592-9192    M/C EMB TOP PCS 4450    8/24/2021   1
STITCHING PRODUCT   TH11592-9193    BACK CUT PCS    4000    8/14/2021   2
STITCHING PRODUCT   TH11592-9193    BACK CUT PCS    6200    8/23/2021   2
STITCHING PRODUCT   TH11592-9259    LINNING CUT PCS 4000    8/14/2021   3
STITCHING PRODUCT   TH11592-9259    LINNING CUT PCS 2000    8/16/2021   3
STITCHING PRODUCT   TH11592-9259    LINNING CUT PCS 6200    8/23/2021   3

我需要基于 articlecode

的列数

使用DENSE_RANK我们可以尝试:

SELECT *, DENSE_RANK() OVER (ORDER BY articlecode) AS rown
FROM Table_1
ORDER BY articlecode, createdon;