Re: How to get the 0 counts in a group by ?
From: Steve Kass (skass_at_drew.edu)
Date: 02/16/04
- Next message: Steve Kass: "Re: Question for Microsoft guys"
- Previous message: Anith Sen: "Re: sql syntax question - returning 3 test rows - use "VALUES"?"
- In reply to: Peter Daniels: "How to get the 0 counts in a group by ?"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 16 Feb 2004 16:29:54 -0500
Peter,
In case David Portas's suggestion to add (select 0 union all select 1)
as T(ans) to the query seems a bit out of the blue:
It sounds like you want this:
Grade 04 Reading ... 1 0*
in your result set despite the fact that your source table never has the
values Grade 04, Reading, and 1 in the same row. You generally can't
produce results that aren't in your data ;) Once you realize that you
need 0 and 1 in the output for all (col1, col2) pairs, regardless of
whether they appear in your data, you can think of adding a table
containing both 0 and 1.
SK
Peter Daniels wrote:
>My table has data in it that includes a flag value - AnsweredFlag.
>I'm having trouble when I want to group the data and report on how
>many in the group were ansered and how many were not. For example, if
>a group of data has only rows with AnsweredFLag = 0, then I get no
>returned row with a count of 0 for that group and AnsweredFLag = 1.
>I'd like top see something like:
>
><col1> <col2> ... <AnsweredFlag> <Count>
>Grade 04 Reading ... 0 35
>Grade 04 Reading ... 1 0*
>Grade 04 Writing ... 0 0*
>Grade 04 Writing ... 1 3
>...
>
>..but I can't seem to get the zero counts (*).
>
>I have been unsuccessful with "WITH ROLLUP" as well as various
>attempts at CROSS JOINS, OUTER JOINS, etc. I know this can be done
>w/o a cursor (the current implementation), but I just can't seem to go
>int th right direction.
>
>TIA,
>
>-Peter
>
>
- Next message: Steve Kass: "Re: Question for Microsoft guys"
- Previous message: Anith Sen: "Re: sql syntax question - returning 3 test rows - use "VALUES"?"
- In reply to: Peter Daniels: "How to get the 0 counts in a group by ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|