Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Group by: Not getting expected output

Group by: Not getting expected output

From: Sameer <dolpheen_at_gmail.com>
Date: 10 May 2006 04:45:09 -0700
Message-ID: <1147261509.206264.267440@g10g2000cwb.googlegroups.com>


Please consider the query:

SELECT tcode,
  COUNT(*) AS GradeEq2to3
FROM info
WHERE tavg >= 2
 AND tavg < 3
GROUP BY tcode
ORDER BY tcode;

The info table contains the fields tcode and tavg. When I run the query, I got the expected output i.e. tcode and the corresponding count for tavg for the specified condition. But the query ignores the 0 count i.e. I want to display all the tcode's. If this condition is not satisfied for a particular tcode and the corresponding entry should be 0.

For example, presently I am getting the output as:

TCode       GradeEq2to3

......... ....................
ABC 16 CDE 12 EFG 13 GHI 14

There are entries for which the condition (tavg >= 2  AND tavg < 3) is not satisfied. I want output in the format.

TCode       GradeEq2to3

......... ....................
ABC 16 XYZ 0 CDE 12 EFG 13 GHI 14 ZAB 0

How to alter/design query for the same?

-Sameer Received on Wed May 10 2006 - 06:45:09 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US