Counting columns that match input data

Counting columns that match input data

am 04.05.2006 03:26:44 von jj

Is it possible to count the number of columns that match certain conditions
and return a single value?

For example in the database we have a record where:

Column 1 = Male
Column 2 = A
Column 3 = B
Column 4 = D
Column 5 = M

And the data to be used for the query is:

Column 1 = Male
Column 2 = D
Column 3 = B
Column 4 = Z
Column 5 = M

I would like to be able to return all records where Column 1 = Male and also
return how many columns (from Column 2 through 5) match the data input. In
this case the number would be 2 since Column 3 and Column 5 in the database
match the data used for the query. If no columns match the input data, the
number returned would be 0.

Does that make sense? Can anybody help me out with a sql statement that
will do this? It would be greatly appreciated.

Thanks!

Re: Counting columns that match input data

am 04.05.2006 05:18:35 von jj

I figured out a way to do it. I can use a series of IF() functions and add
them together.



"JJ" wrote in message
news:44595836$0$22508$c3e8da3@news.astraweb.com...
> Is it possible to count the number of columns that match certain
> conditions and return a single value?
>
> For example in the database we have a record where:
>
> Column 1 = Male
> Column 2 = A
> Column 3 = B
> Column 4 = D
> Column 5 = M
>
> And the data to be used for the query is:
>
> Column 1 = Male
> Column 2 = D
> Column 3 = B
> Column 4 = Z
> Column 5 = M
>
> I would like to be able to return all records where Column 1 = Male and
> also return how many columns (from Column 2 through 5) match the data
> input. In this case the number would be 2 since Column 3 and Column 5 in
> the database match the data used for the query. If no columns match the
> input data, the number returned would be 0.
>
> Does that make sense? Can anybody help me out with a sql statement that
> will do this? It would be greatly appreciated.
>
> Thanks!
>