how to count data in different ids

  • hi........

    i have table like this.

    id product

    --------------------

    1 cello

    2 cello

    3 cello

    4 cello

    5 cello grip

    6 cello grip

    i need output like this

    ----------------------

    tempid or id product count

    ------------------------------

    1 cello 4

    2 cellogrip 2

    could u please help me ........for that

    Thanks
    Dastagiri.D

  • You question is not very clear to me, but I think this should do the trick:

    SELECT MIN(id), Product, COUNT(*)

    FROM MyTable

    GROUP BY Product

    -- Gianluca Sartori

  • yes this is correct answer for me thanks..

    Thanks
    Dastagiri.D

  • I believe this would do (not near an SQL Server right now so can't test)...

    SELECT ROW_NUMBER() OVER (ORDER BY Product) AS TempID,

    Product, COUNT(*)

    FROM MyTable

    GROUP BY Product

    If that doesn't get it because of a GROUP BY error, post back.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

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

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