Re: Counting two columns with where causes for each

From: Charlie Edwards <Charlie3101_at_hotmail.com>
Date: 18 Sep 2002 07:10:07 -0700
Message-ID: <db479d88.0209180610.4ab671e0_at_posting.google.com>


john_w_keller_at_yahoo.com (John Keller) wrote in message news:<12c0a6d6.0209171449.7b641693_at_posting.google.com>...
> That's good; I didn't think of using decode + sum in lieu of count.
>
> My solution using views would've worked if I'd remembered to put a
> 'group by' clause in the final query. But nevermind, this is much
> neater.
>
> (btw, the count function happens to count rows with non-null values,
> so it works on date_for_raise only because you happen to want a count
> of non-null values in that column.)
>
> john
>
>
> Charlie3101_at_hotmail.com (Charlie Edwards) wrote in message news:<db479d88.0209170521.1e02e76e_at_posting.google.com>...
> >
> > Am I misunderstanding something here?
> > Whats wrong with (assuming it's job 15 you want, not 18) ...
> >
> > SELECT district,
> > race,
> > SUM(DECODE(job,15,1,0)) jobcount,
> > COUNT(date_for_raise) datecount
> > FROM info
> > GROUP BY district,race;
> >
> > CE

I tend to use SUM as a habit, though this would have worked just as well:

SELECT district,

       race,
       COUNT(DECODE(job,15,'Job 15 here!',NULL)) jobcount,
       COUNT(date_for_raise) datecount

  FROM info
GROUP BY district,race;

CE Received on Wed Sep 18 2002 - 16:10:07 CEST

Original text of this message