Click here to get back home

Counting columns that match input data

 HomeNewsGroups | Search | About
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Counting columns that match input data JJ 05-03-2006
Get Chitika Premium
Posted by JJ on May 3, 2006, 9:26 pm
Please log in for more thread options
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!



Posted by JJ on May 3, 2006, 11:18 pm
Please log in for more thread options
I figured out a way to do it. I can use a series of IF() functions and add
them together.



> 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!
>



Similar ThreadsPosted
Help with counting total items using hierarchical data structure August 1, 2007, 1:27 am
MATCH AGAINST HELP match exact word August 9, 2006, 2:14 pm
Counting rows assigned to index value? October 5, 2005, 3:32 am
capturing user input June 16, 2007, 3:01 am
Input and Display Records With Same Script? May 18, 2006, 9:10 am
Navicat Frontend: Possible to accept keyboard input to set user variable? January 10, 2006, 6:37 pm
FULLTEXT MATCH() January 8, 2007, 11:11 am
MATCH Fulltext search July 30, 2005, 10:49 pm
returning relevane of match queries as a percentage August 4, 2006, 10:48 am
Partially updating records based on pattern match October 5, 2005, 1:33 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap