Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Problem returning
Can anyone help?
I have written the following query based on a decode statement that will do counts on certain grouped rows. I have a problem in that when the decode evaluates a blank column i.e. ... null, 'SPACES' nothing is shown in the results set i.e. SPACES 0. This is due to there being no rows that satisfy the query i.e. count=0. However, if I change the test data and allow a row to satisfy the query i.e. there is a null field in the results then SPACES row entry is shown in the result i.e. SPACES 1. Question is how would you change the query so that you would get an entry in the results when COUNT = 0 i.e. SPACES 0 ?
SELECT DECODE(SUBSTR(tab1.col1,1,1),
'L', 'LOTH', 'S', 'STRAT',
'D', 'DUMF', 'C', 'CEN', 'F', 'FIF',
'T', 'TAYS', 'G', 'GRAMPS', 'N', 'NORTH',
null , 'SPACES', 'OTHERS')DECODE, COUNT(tab1.col4) COUNT
'L', 'LOTH', 'S', 'STRAT',
'D', 'DUMF', 'C', 'CEN', 'F', 'FIF',
'T', 'TAYS', 'G', 'GRAMPS', 'N', 'NORTH',
null , 'SPACES', 'OTHERS');
Result
DECODE COUNT
------ ----------
CEN 25 DUMF 31 FIF 24 GRAMPS 29 LOTH 35 NORTH 22 OTHERS 35 STRAT 577 TAYS 35
Cheers
Andrew
Received on Fri Sep 27 2002 - 09:19:29 CDT