pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedCount Columns
2+ messages / 2 participants
[nested] [flat]
* Count Columns
@ 2005-02-16 18:09 Ray Madigan <ray@madigans.org>
0 siblings, 1 reply; 2+ messages in thread
From: Ray Madigan @ 2005-02-16 18:09 UTC (permalink / raw)
To: pgsql-sql
I haven't done very many complex queries in sql, and maybe Im thinking about
my problem wrong but:
Is there a way to count the number of null or not null columns in a row and
have an output column that has that count as the value?
I want to create a ranking of the row based upon the number of not null
columns are in the row. I want to have to use as few seperate queries as
possible.
The table that i want to do the query on is either a view or a temporary
table, I guess depending on if I can do this easily or if brut force is
required, Or if I have to think of a new way to solve my problem.
The table is like
CREATE TABLE myTbl ( name varchar(5) primary key, a varchar(5), b
varchar(5), c varchar(5) );
ending table looks like
name | a | b | c |
foo | A | | C |
bar | A | B | |
baz | A | B | C |
and I want the result to look like
foo 2
bar 2
baz 3
Thanks in Advance
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Count Columns
@ 2005-02-16 19:58 Bruno Wolff III <bruno@wolff.to>
parent: Ray Madigan <ray@madigans.org>
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Wolff III @ 2005-02-16 19:58 UTC (permalink / raw)
To: Ray Madigan <ray@madigans.org>; +Cc: pgsql-sql
On Wed, Feb 16, 2005 at 10:09:05 -0800,
Ray Madigan <ray@madigans.org> wrote:
>
> Is there a way to count the number of null or not null columns in a row and
> have an output column that has that count as the value?
One way to do this would be to create a CASE clause for each column that
returns 1 or 0 depending on whether the column is null or not and add
these expressions up.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-02-16 19:58 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-02-16 18:09 Count Columns Ray Madigan <ray@madigans.org>
2005-02-16 19:58 ` Bruno Wolff III <bruno@wolff.to>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox