You are here: Getting count with multiple fields « MsSQL Server « IT news, forums, messages
Getting count with multiple fields

Posted by Alex on 09/06/05 17:23

Hi all,

I'm running into a road block, and I know I've done this before. I'm
getting fields from two tables, and I need to do a count of similar
items with it showing some extra info.

Here's my fields:
Log.LogId - Int
Log.LogDispatcherID - Int
Officer.OfficerID - Int
Officer.OfficerFirstName - Varchar
Officer.OfficerLastName - Varchar

I can get the info I need without a count with this:

select a.LogID,
a.LogDispatcherID,
b.OfficerFirstname + ' ' + b.OfficerLastname as OfficerName
from [Log] a, Officer b
where a.LogAssigned1 = b.OfficerID

But when I try to add a count and group-by it errors out:

select Count(a.LogID) as LogCount,
a.LogDispatcherID,
b.OfficerFirstname + ' ' + b.OfficerLastname as OfficerName
from [Log] a, Officer b
where a.LogAssigned1 = b.OfficerID
Group By a.LogID

I've done this before, but this isn't working. It's giving the error
"it is not contained in either an aggregate function or the GROUP BY
clause" for each field other then LogID.

How can I do this? I want output similar to this:

LogCount LogDispatchID OfficerName
3 34 Tom Jones
4 22 John Smith
.... Etc

Thanks for any suggestions or ideas...

Sam Alex

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация