Script to count values

  • Hi everyone, obviously I'm a newbie and my question might show that. I work in a school board and I am trying to create a view that holds two pieces of information, the school code the the current count of active students. I would like to pull this from a table that holds all of the students and the school they are currently attending. Now I know I could script the view and manually enter the variables for each school code and do the count and dump it in. What I am looking at doing though is dynamically running through the table finding all of the individual school codes and doing a count on that school code. Clear as mud?? lol. Anyway I'm not sure how to even approach this or if it can even be done. If you need more info let me know. Thanks. 🙂

  • At a complete guess, is this what you meant ?

    Select SchoolCode,Count(*)

    from students

    group by SchoolCode

    If not please provide DDL (data definition language) sample data and expect output



    Clear Sky SQL
    My Blog[/url]

  • Thanks Dave!! That worked perfectly. I forgot about the groupby function. Thanks! 😀

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply