purpledawn
Programmer
The issue I am having is with Oracle, and I think that it applies to ANSI SQL too. Please excuse me for not taking the time to do that research.
I have a table as follows
Field1 Field2
------ ------
A 1
A 4
B [null]
B [null]
C [null]
I am writing a query on this table as follows
SELECT field1, COUNT(field2)
FROM table
WHERE field2 BETWEEN 1 AND 3
GROUP BY field1
which gives the result
Field1 Count(Field2)
------ -------------
A 1
The problem is that I would like the result to look like
Field1 Count(Field2)
------ -------------
A 1
B 0
C 0
but I can't figure it out. I have tried the various functions you can do with count (ALL, *, DISTINCT), as well as NVL on both fields, but I either get errors or the same result. I also tried a really wacky idea of an outer self join, but that didn't work either.
Any suggestions?
I have a table as follows
Field1 Field2
------ ------
A 1
A 4
B [null]
B [null]
C [null]
I am writing a query on this table as follows
SELECT field1, COUNT(field2)
FROM table
WHERE field2 BETWEEN 1 AND 3
GROUP BY field1
which gives the result
Field1 Count(Field2)
------ -------------
A 1
The problem is that I would like the result to look like
Field1 Count(Field2)
------ -------------
A 1
B 0
C 0
but I can't figure it out. I have tried the various functions you can do with count (ALL, *, DISTINCT), as well as NVL on both fields, but I either get errors or the same result. I also tried a really wacky idea of an outer self join, but that didn't work either.
Any suggestions?