I need a query to obtain following result. The aim is to count the repeated value of a column in articlecode. Also the repeated rows should be truncated or displayed.
Table_1: (Before using query)
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: (After using query, the table should look like this below)
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
i need rown colume count based on articlecode
CodePudding user response:
Using DENSE_RANK
we can try:
SELECT *, DENSE_RANK() OVER (ORDER BY articlecode) AS rown
FROM Table_1
ORDER BY articlecode, createdon;