Count Columns

From: "Ray Madigan" <ray(at)madigans(dot)org>
To: "Pgsql-Sql" <pgsql-sql(at)postgresql(dot)org>
Subject: Count Columns
Date: 2005-02-16 18:09:05
Message-ID: AEEJIDLCICLNLPOJHFEEIEDDFCAA.ray@madigans.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message KÖPFERL Robert 2005-02-16 18:33:55 Re: Relation in tables
Previous Message lucas 2005-02-16 16:43:01 Relation in tables