Search code examples
sqlnetezza

Aggregating across Columns SQL-Netezza


I want to count the number of times an ICD code appears across columns. The first five columns are the data and the three highlighted columns represent my desired output.

data with desired output

I have tried simple case when statement but it just flagged rather than summed across column. Is there any function that helps me to get the desired output(three highlighted columns).

Any help to calculate the desired output is welcomed.


Solution

  • I solved it by pivoting all diagnosis column into one. And then using a case when statement. This process was much faster.