472,114 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,114 software developers and data experts.

Counting columns that match input data

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!
May 4 '06 #1
1 2045
JJ
I figured out a way to do it. I can use a series of IF() functions and add
them together.

"JJ" <no*****@thank.you> wrote in message
news:44**********************@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!

May 4 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by SL_McManus | last post: by
5 posts views Thread by Axial | last post: by
5 posts views Thread by explode | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.