I have a table with Lots of cost columns for each Key TableA
SK1 SK2 Col1 Col2 Col3..... Col50 Flg(Y/N)
1 2 10 20 30 ...... 500 Y
1 2 10 20 30 ...... 500 N
2 2 10 20 30 ...... 500 N
I need to aggregate(sum) of all values and then check if there are any values with Y then add them to new tableB. Here table A record combination (1,2) for (sk1,sk2) should be returned.
The i have written query is to select lisr of all cols and add as group by. We have lots of data so this query is taking too long to run. Any chance to relook into this and do so that it can become faster.
select Sk1, Sk2, nvl(sum(col3),0), nvl(sum(col4))0, ..... nvl(sum(col50)) from table A group by Sk1, Sk2
Iam using this as part of large query where in many other calculations are performed on top of this.