oracle - Apply a single case statement to all columns in sql -
i need sum of each column of table. used select sum(col1),col2 etc.
if sum null, need 0, else value of sum. used "select case when sum(col1) null 0 else sum(col1) end sum_col1".
i have around 40 such columns in table. need write " case when sum(col n) then..." 40 times in query?
im working on oracle 9 g. thanks
i have around 40 such columns in table. need write " case when sum(col n) then..." 40 times in query?
short answer: yes.
longer answer: might able use kind of dynamic sql generate statement automatically column metadata. might not worth trouble, can copy-paste statement in query editor. things considered, having table 40 columns need sum, indicates bad data model design. when working badly designed data model, pay price @ query time...
Comments
Post a Comment