PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.db.ms-sqlserver > How to select count records that "contain" data?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
How to select count records that "contain" data?

Réponse
 
LinkBack Outils de la discussion
Vieux 19/09/2007, 23h45   #1
Terry Olsen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut How to select count records that "contain" data?

I have a table in SQL Server that looks like this:

Name Status
---------------------------
Steve Complete
Steve In Queue
John Pending
John Complete
John Complete
Tim In Queue

I need to throw a query at this that will return the number of
"Complete"'s that each person has. So the result would look like:

Name Completed
----------------------------
Steve 1
John 2
Tim 0

Can anyone out with what a query statement would look like to get
the desired output?


*** Sent via Developersdex http://www.developersdex.com ***
  Réponse avec citation
Vieux 20/09/2007, 00h38   #2
Spook
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to select count records that "contain" data?

I think this should work:


Select Name, Count (Status)
from <<tablename>>
where status ='complete'
group by Name
order by Name



"Terry Olsen" <tolsen64@hotmail.com> wrote in message
news:46f19892$0$508$815e3792@news.qwest.net...
>I have a table in SQL Server that looks like this:
>
> Name Status
> ---------------------------
> Steve Complete
> Steve In Queue
> John Pending
> John Complete
> John Complete
> Tim In Queue
>
> I need to throw a query at this that will return the number of
> "Complete"'s that each person has. So the result would look like:
>
> Name Completed
> ----------------------------
> Steve 1
> John 2
> Tim 0
>
> Can anyone out with what a query statement would look like to get
> the desired output?
>
>
> *** Sent via Developersdex http://www.developersdex.com ***



  Réponse avec citation
Vieux 20/09/2007, 00h47   #3
Terry Olsen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to select count records that "contain" data?

Yes, that works. But it doesn't show the row with no completes. So
unless a person has at least one complete, they won't show.

This will work for me, but is there a way to get it to include the
people with no completes?

Thanks again!


*** Sent via Developersdex http://www.developersdex.com ***
  Réponse avec citation
Vieux 20/09/2007, 01h19   #4
Ed Murphy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to select count records that "contain" data?

Terry Olsen wrote:

> Yes, that works. But it doesn't show the row with no completes. So
> unless a person has at least one complete, they won't show.
>
> This will work for me, but is there a way to get it to include the
> people with no completes?


select Name, count(case Status when 'Complete' then 1 else 0 end)
from <<tablename>>
group by Name
order by Name
  Réponse avec citation
Vieux 20/09/2007, 08h29   #5
Arto V Viitanen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to select count records that "contain" data?

Ed Murphy wrote:
> Terry Olsen wrote:
>
>> Yes, that works. But it doesn't show the row with no completes. So
>> unless a person has at least one complete, they won't show.
>> This will work for me, but is there a way to get it to include the
>> people with no completes?

>
> select Name, count(case Status when 'Complete' then 1 else 0 end)
> from <<tablename>>
> group by Name
> order by Name


I guess you meant


select Name, sum(case Status when 'Complete' then 1 else 0 end)
from <<tablename>>
group by Name
order by Name

--
Arto Viitanen
  Réponse avec citation
Vieux 21/09/2007, 04h07   #6
Ed Murphy
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to select count records that "contain" data?

Arto V Viitanen wrote:

> Ed Murphy wrote:
>> Terry Olsen wrote:
>>
>>> Yes, that works. But it doesn't show the row with no completes. So
>>> unless a person has at least one complete, they won't show.
>>> This will work for me, but is there a way to get it to include the
>>> people with no completes?

>> select Name, count(case Status when 'Complete' then 1 else 0 end)
>> from <<tablename>>
>> group by Name
>> order by Name

>
> I guess you meant
>
>
> select Name, sum(case Status when 'Complete' then 1 else 0 end)


Yes, sorry.
  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 02h03.


É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,11256 seconds with 14 queries