none
Count of 2 distinct columns??? RRS feed

  • Question

  • how do I get an alias called Qty that is based on the following: Count of records in company & month

    ??

    Monday, October 21, 2019 2:11 AM

All replies

  • Hi ,

    Thank you for your posting,

     

    Could you  please share us your table structure (CREATE TABLE …) and some sample data (INSERT INTO…) along with your expected result? So that we’ll get a right direction and make some test.

    Also , I do an example . Please refer to it.

    IF OBJECT_ID('test') IS NOT NULL drop table  test   
    go 
    create table test (
    company varchar(10),
    month int ,
    im_value int 
    )
    insert into test values 
    ('A',8,11),('A',11,155),('A',11,169),
    ('B',5,11),('B',5,5643),('B',5,55)
    
    select company,month,count(*) Qty  from test group by  company,month
    /*
    company    month       Qty
    ---------- ----------- -----------
    B          5           3
    A          8           1
    A          11          2
    */


    Best Regards,

    Rachel


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 21, 2019 3:31 AM
  • This is the table structure 

    Company : DMPCompanyName

    Month : derived from DateReceived

    Dollars : AmountOfPayment

    Qty : Count of records in company & month

    Monday, October 21, 2019 3:46 AM
  • Hi ,

    Thank you for your reply.

    Could you  please share us your table structure (CREATE TABLE …) and some sample data (INSERT INTO…) along with your expected result? (Just like above script )So that we’ll get a right direction and make some test.

    Thank you in advance for your understanding.

    Best Regards,

    Rachel 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 21, 2019 5:37 AM