Results 1 to 3 of 3

Thread: View : name + count GROUP BY

  1. #1
    Join Date
    Apr 2006
    Posts
    178

    View : name + count GROUP BY

    Hi

    for MS SQL 2000/2500

    I am having a table with Products, a Product be many time in the table

    I need a view to return a GROUP BY on Name + Reference and the Count(Name)

    Product
    Product_ID int NOT NULL,
    Name varchar (50) Not Null,
    Reference varchar (50) Not Null,
    Infos varchar (255) Null,
    PDate (smalldatetime) Null


    I need a View with 4 columns

    MAX(Product_ID) AS ID, Name, Reference, Count(Name) AS Ct
    GROUP BY Name, Reference



    i can't Get the count in the same view

    thank you for helping

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Aggregate function applies to all columns in group, so you can't do count(name), you have to use count(*)

  3. #3
    Join Date
    Apr 2006
    Posts
    178
    it works fine !

    thank you
    Last edited by anselme; 11-22-2006 at 04:27 PM.

Posting Permissions

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