sql - Number rows based on similar columns -


how number rows base on similar elements in rows. eg. table

id cola  colb 1.   a.       b 2.   a.       c  3.  a.        c 4.   a.       b 5.   b.       6.   b.       

i wish following table

  id cola  colb. grouped  1.   a.       b.     1  2.   a.       c.      2  3.  a.        c.     2  4.   a.       b.     1  5.   b.       a.     3  6.   b.       a.     3 

the logic is: rows id 1and 4 have similar elements in columns , b number same group number. number doesn't play role. rows id 2 , 3 same number.

the easiest thing rank rows according both columns. since rows 2 , 3 seem have same "grouped by" regardless of different case of c vs. c (assuming isn't typo), you'd have rank them according upper (or lower, matter) of columns:

select cola, colb,         rank() on (order upper(cola), upper(colb)) "grouped by"   my_table 

Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -