DENSE_RANK according to particular order
问题 Hi I have a table of data I want to output the dense_rank of the names starting from the first group of names according to sorted dates order. e.g. DROP TABLE MyTable SELECT * INTO MyTable FROM ( VALUES ('2015-12-23', 'ccc'),('2015-12-21', 'aaa'), ('2015-12-20', 'bbb'),('2015-12-22', 'aaa') ) t (date, name) SELECT DENSE_RANK() OVER (ORDER BY name) rank, * FROM MyTable ORDER BY date For the query above I got rank date name 2 2015-12-20 bbb 1 2015-12-21 aaa 1 2015-12-22 aaa 3 2015-12-23 ccc You