PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Graphisme & Infographie > macromedia.dreamweaver > MSSQL Count
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
MSSQL Count

Réponse
 
LinkBack Outils de la discussion
Vieux 10/06/2008, 22h51   #1
MikeL7
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut MSSQL Count

I am trying to write a query that counts records from two tables, but am
getting wrong counts. Basically what i want is this:
SELECT Count(callSched.callID) as callCount, Count(visitSched.visitID) as
visCount, employees.workerNumber, employees.workerName
From employees LEFT OUTER JOIN
callSched on employees.workerNumber = callSched.empID LEFT OUTER JOIN
visitSched on employees.workerNumber = visitSched.wrkID
GROUP BY workerNumber, workerName

I get the proper columns grouped, but am getting 400,000 as the count when it
should be 1500-2000.
Any ideas how to make this return the results?


  Réponse avec citation
Vieux 11/06/2008, 09h03   #2
Dooza
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MSSQL Count

MikeL7 wrote:
> I am trying to write a query that counts records from two tables, but am
> getting wrong counts. Basically what i want is this:
> SELECT Count(callSched.callID) as callCount, Count(visitSched.visitID) as
> visCount, employees.workerNumber, employees.workerName
> From employees LEFT OUTER JOIN
> callSched on employees.workerNumber = callSched.empID LEFT OUTER JOIN
> visitSched on employees.workerNumber = visitSched.wrkID
> GROUP BY workerNumber, workerName
>
> I get the proper columns grouped, but am getting 400,000 as the count when it
> should be 1500-2000.
> Any ideas how to make this return the results?


I don't think a GROUP BY will work in this situtation, what might work
is 2 sub querys, possibly...

SELECT COUNT(SELECT .... ) AS callCount, COUNT(SELECT ....) AS visCount

But I can't be sure.

Steve
  Réponse avec citation
Vieux 12/06/2008, 00h56   #3
MikeL7
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MSSQL Count

I have also done the query seperate and used a union all clause and get the
right results, but the employees are listed twice and the counts are all in the
same column instead of two different one named after their alias.

  Réponse avec citation
Vieux 12/06/2008, 09h32   #4
Dooza
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: MSSQL Count

MikeL7 wrote:
> I have also done the query seperate and used a union all clause and get the
> right results, but the employees are listed twice and the counts are all in the
> same column instead of two different one named after their alias.
>


I can't see using a UNION would , you need to do something like I
suggested, did that not work?

Steve
  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 07h15.


É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,10516 seconds with 12 queries