|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 me out with a sql statement that will do this? It would be greatly appreciated. Thanks! |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
I figured out a way to do it. I can use a series of IF() functions and add
them together. "JJ" <no_spam@thank.you> 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 me out with a sql statement that > will do this? It would be greatly appreciated. > > Thanks! > |
|
![]() |
| Outils de la discussion | |
|
|