COUNT function in SQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jhayes7781
    New Member
    • Mar 2007
    • 9

    COUNT function in SQL

    I am using the COUNT function in SQL. I am getting it to display the total number of occurrences specified in my criteria. However, I would like for it to display it to show the record in the field for each count. Any suggestions?
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Not clear to me. Show some table records and what you exactly are looking for.

    Ronald :cool:

    Comment

    • jhayes7781
      New Member
      • Mar 2007
      • 9

      #3
      select count (distinct field name)
      from table
      where field name='X'

      The results yield
      Distinct field name
      Count=11

      I want it to show each of those 11 unique counts and all the records assoicated with them. That make more sense?

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Not really. Maybe you mean the following statement (without the count?)
        Code:
        select * from table where fieldname='X'
        I don't think so, but you want to see all 11 records, so this will show them.

        Ronald :cool:

        Comment

        • jhayes7781
          New Member
          • Mar 2007
          • 9

          #5
          Yeah that is pretty close...i just want to get the record that its couting displayed. Say if your table had a 11 different kinds of shoes but shoe A. may be in there 20 times. I would want it to display:

          Shoe A: 10
          Shoe B: 5
          Shoe C: 8
          etc... for all 11 of the records it counted.

          Any help?

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Something like
            Code:
            SELECT shoe, count(shoe) FROM tablename GROUP BY(shoe);
            Ronald :cool:

            Comment

            Working...