Count Distinct

Posted on 2005-05-04
Last Modified: 2010-03-19
Hi..Please Help

I have a table with is a log of users interaction with a system.  each time the user uses the system it stamps the db with various details.  What i would like to do is create a query that shows me a count against each of the customers id


user            date           action
abc           1.00 pm          A
xyz           1.05 pm           B
abc           1.10pm           C

i would liekt o generate a query that gives the result

user                       hits
abc                          2
xyz                           1

Thank you for your help

Question by:cafferm
    LVL 28

    Accepted Solution

    Try this:

    SELECT User, COUNT(*)
    FROM YourTable
    GROUP BY User
    LVL 28

    Expert Comment

    SELECT User, COUNT(*) AS Hits
    FROM YourTable
    GROUP BY User

    Author Comment

    Now thats fast - thank you very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Suggested Solutions

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
    Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
    Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now