X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A1B698B9B6F for ; Wed, 16 Feb 2005 19:16:27 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 36822-07 for ; Wed, 16 Feb 2005 19:15:56 +0000 (GMT) Received: from smtp3.pacifier.net (smtp3.pacifier.net [64.255.237.173]) by svr1.postgresql.org (Postfix) with ESMTP id 0D6828BA53A for ; Wed, 16 Feb 2005 19:00:56 +0000 (GMT) Received: from nefesh (ip16.gte154.dsl-acs2.sea.iinet.com [207.202.154.16]) by smtp3.pacifier.net (Postfix) with SMTP id 9D23A6E40E for ; Wed, 16 Feb 2005 11:00:55 -0800 (PST) From: "Ray Madigan" To: "Pgsql-Sql" Subject: Count Columns Date: Wed, 16 Feb 2005 10:09:05 -0800 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/170 X-Sequence-Number: 20281 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