Count Columns
Count Columns
От:
"Ray Madigan" <ray@madigans.org>
Дата:
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
Re: Count Columns
От:
Bruno Wolff III <bruno@wolff.to>
Дата:
On Wed, Feb 16, 2005 at 10:09:05 -0800, Ray Madigan 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.