Distinct Count

Posted on 2005-05-05
Medium Priority
Last Modified: 2010-03-19

I have a table which holds various details i need to count the amount of times an item appears.  But i need to only count the item against 1 id  - i think i'm confusing things - so here's what i need

Logid                  LogType                     Info
035621                  FILEH                       Log on
035622                  FILE                         Log on
035622                  FILE                         Check Something
035622                  FILE                         Log off
035623                  FILEH                       Log off
035623                  FILEH                       Log on
035624                  FILEH                       Log on

So basically i need to count how many times File and FileH appear against the Logids

So the result i need from this is

Logtype                             Count
FILE                                     1
FILEH                                   3


Question by:cafferm
  • 2
LVL 33

Expert Comment

ID: 13933476
//r u asking for this ?
select count(*),logtype
from tablename
group by logtype
LVL 33

Accepted Solution

sajuks earned 2000 total points
ID: 13933489
select count(distinct logid),logtype from table
group by logtype;

Author Comment

ID: 13933503
Thats it thanks

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question