Skip to content
Advertisement

Count of two columns while keeping the remaining columns

I need to figure out how to count the combinations of two columns while keeping the rest of the columns visible. This is what I have

The code above produces Columns 1 – Column 4 however I need a count of the combination of column 2 and column 4(which is the result of a case statement) as the example below. I don’t know how groupby will work because I will need to display all the columns. How do I produce the column of ‘Count_of_Col24’?

Column1 Column2 Column 3 Column4 Count_of_Col24
1 123 AB BA 1
2 123 AC BB 2
3 123 AD BB 2

Advertisement

Answer

You can try to use COUNT window function, PARTITION BY your logic which you want count of the combination.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement