By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE T(
ID INT,
date VARCHAR(50),
item VARCHAR(50)
);
insert into T values (101,'20220201', 'pencil');
insert into T values (105,'20220201', 'pencil');
insert into T values (120,'20220214', 'desk');
insert into T values (125,'20220219', 'tongs');
SELECT *
FROM (
SELECT *,dense_rank() OVER(ORDER BY date, item) rnk
FROM T
) t1
ID | date | item | rnk |
---|---|---|---|
101 | 20220201 | pencil | 1 |
105 | 20220201 | pencil | 1 |
120 | 20220214 | desk | 2 |
125 | 20220219 | tongs | 3 |