pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ray Madigan <ray@madigans.org>
To: Pgsql-Sql <pgsql-sql@postgresql.org>
Subject: Count Columns
Date: Wed, 16 Feb 2005 10:09:05 -0800
Message-ID: <AEEJIDLCICLNLPOJHFEEIEDDFCAA.ray@madigans.org> (raw)

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




view thread (2+ messages)  latest in thread

Message-ID: <AEEJIDLCICLNLPOJHFEEIEDDFCAA.ray@madigans.org>
Permalink:  ../AEEJIDLCICLNLPOJHFEEIEDDFCAA.ray@madigans.org/
Also on:    postgresql.org/message-id/AEEJIDLCICLNLPOJHFEEIEDDFCAA.ray@madigans.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: ray@madigans.org
  Subject: Re: Count Columns
  In-Reply-To: <AEEJIDLCICLNLPOJHFEEIEDDFCAA.ray@madigans.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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