Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    19
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Counting Entries - Help Needed :)

    Hi Everyone,

    Thanks for your help!

    I have a table that has one row entry per unique event. Here's the current structure:

    type varchar(1)
    employee varchar(50)
    routeLoaded varchar(10)
    routePAL varchar(10)
    address varchar(100)
    comments varchar(100)
    timestamp timestamp

    Here are some example rows:

    0 Todd 1B 1E "3016 Queso Ln" 2011-10-28 10:39:57
    0 Larry 9E 7C "509 Gordita Ln" 2011-10-28 10:40:01
    0 Larry 9E 7C "2087 Fiesta Ln" 2011-10-28 10:40:05
    0 Matt 2B 2C "535 Taquito Ln" 2011-10-28 10:40:12
    0 Matt 2B 2C "670 Burrito Ln" 2011-10-28 10:40:17
    0 Matt 2B 2A "2137 Taco Ln" 2011-10-28 10:40:23

    There aren't any unique fields; there are many entries with the same employee, address, etc.

    What I want to do is display a count of how many entries in this table each employee has.

    So, for the example above, the result I want is:

    Matt 3
    Larry 2
    Todd 1

    I had expected to be able to use Count, but as far as I can tell I can't do what I want with Count in my query.

    Thanks for your help,
    Ben

  • #2
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    show us what you have tried and why you think count won't work.

  • #3
    New Coder
    Join Date
    Sep 2011
    Location
    Omaha, NE
    Posts
    49
    Thanks
    1
    Thanked 6 Times in 5 Posts
    Code:
    select count(*) from table_name where column='whatyouwantcounted';
    There ya go.
    Web Design Omaha Ne
    Hold yourself responsible for a higher standard than anybody expects of you. Never excuse yourself.
    - Henry Ward Beecher

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,437
    Thanks
    75
    Thanked 4,372 Times in 4,337 Posts
    Code:
    SELECT employee, COUNT(*) as recordsPerEmployee
    FROM tablename
    GROUP BY employee
    ORDER BY employee
    Or you could do
    Code:
    ORDER BY recordsPerEmployee DESC
    or or or...but the important part is the GROUP BY.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •