PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Logiciels d'hébergement > mailing.database.mysql > Counting columns that match input data
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Counting columns that match input data

Réponse
 
LinkBack Outils de la discussion
Vieux 04/05/2006, 03h26   #1
JJ
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Counting columns that match input data

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!


  Réponse avec citation
Vieux 04/05/2006, 05h18   #2
JJ
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Counting columns that match input data

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



  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08106 seconds with 10 queries