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 12 of 12
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Row Counting Question

    I have a table set up for class registrations. All the classes registered are put into that table. Is there a way I can have asp count the number of rows with Productive Organic Gardening, and the other class names to display the number registered, or am I goingto have to redo my whole scheme and have separate tables for each class?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The "Sum" function in SQL should be able to get you what you want.


    Edit--- I said Sum but as others have pointed out, Count is the right function.
    Last edited by Roy Sinclair; 09-09-2004 at 07:34 PM.
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #3
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    And it sounds like you might need to use Count() as well.
    OracleGuy

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    like:
    Code:
    SELECT COUNT(*) FROM yourtablename GROUP BY yourcolumnamewhichholdstheclassname
    I am the luckiest man in the world

  • #5
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So how would I have that display the number as in

    Class name - 3 registrations

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Code:
    SELECT COUNT(*), yourcolumnamewhichholdstheclassname FROM yourtablename GROUP BY yourcolumnamewhichholdstheclassname
    Should return the count and the class name then.
    OracleGuy

  • #7
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oracleguy
    Code:
    SELECT COUNT(*), yourcolumnamewhichholdstheclassname FROM yourtablename GROUP BY yourcolumnamewhichholdstheclassname
    Should return the count and the class name then.
    that didn't work, but when I changed it to "SELECT COUNT(*) as classid FROM informal_classes GROUP BY classid" it did, however, I still can't get it to display the actual class name, which is in another column (called classname)

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try:

    Code:
    SELECT COUNT(distinct classid),classname FROM informal_classes GROUP BY classname
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #9
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Roy Sinclair
    Try:

    Code:
    SELECT COUNT(distinct classid),classname FROM informal_classes GROUP BY classname
    I get "Syntax error (missing operator) in query expression 'COUNT(distinct classid)'."

  • #10
    Senior Coder
    Join Date
    Jun 2002
    Location
    Zwolle, The Netherlands
    Posts
    1,120
    Thanks
    2
    Thanked 31 Times in 31 Posts
    Code:
    select count(*) as registrations, classname from informal_classes group by classname
    I am the luckiest man in the world

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Wichita
    Posts
    3,880
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What SQL engine?
    Check out the Forum Search. It's the short path to getting great results from this forum.

  • #12
    New Coder
    Join Date
    Apr 2004
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Roelf
    Code:
    select count(*) as registrations, classname from informal_classes group by classname
    Excellent, that works. Thanks a lot everyone. this forum is the best place I've ever visited.


  •  

    Posting Permissions

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