How to select count based on two columns combination

  • I have table name sample  and has below records. The Result I am expecting is mentioned below to this table.

    I want count of  (  stockid X  Lineitemitd ) combination which is >=1

    Sample

    idstockidCategorylineitemid
    102debits1
    114debits1
    125debits1
    72deposits1
    84deposits1
    95deposits1
    54sales1
    65sales1
    12sales1
    22purchases21
    34purchases21
    45purchases21
    132other26
    144other26
    155other26

    Result Expected:

    idstockidCategorylineitemidCount
    102debits13
    114debits13
    125debits13
    72deposits13
    84deposits13
    95deposits13
    54sales13
    65sales13
    12sales13
    22purchases211
    34purchases211
    45purchases211
    132other261
    144other261
    155other261

  • You just use both columns in your PARTITION BY clause.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Hi Drew,

    Thanks for the reply. I will try that.

  • Can you kindly elaborate how you got count=3 and count=1?

    Saravanan

    Saravanan

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

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