'How to select most frequent value with condition for multiple columns in netezza?

I want to get the most frequent value for each column. If it has the same frequent it will return 'equal'.

I have data like below table and I use netezza.

number    cat1     cat2    
      1          a       w
      1          a       w
      1          b       q
      1          c       q
      2          b       w
      2          b       w
      2          b       e
      3          d       w
      3          d       w
      3          e       q
      3          e       q

My expected output:

number     cat1     cat2    
  1          a     equal
  2          b       w
  3        equal   equal

ps. I have about 30 categorical columns in my real data.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source