You must Sign In to post a response.
  • Category: SQL Server

    SQL summary based on condition

    Hi All,

    How can I get the desired summary in SQL query based on some conditions.

    Please find my attached screen shot on next thread.

    Thanks,
    Ram Prasad
  • #768965
    Hi,

    Please find my attached screen shot.

    Thanks,
    Ram Prasad

    Thanks,
    Ram Prasad

    Delete Attachment

  • #768966
    Hi,

    If it is possible for will the table come like,



    LINE-1 NO 25
    LINE-1 YES 25


    ?

    Thanks,
    Mani

  • #768967
    Hi Manigandan,

    There is no possibility of different Status for same Line No.

    Thanks,
    Ram Prasad

    Thanks,
    Ram Prasad

  • #768973

    Hi,

    Kindly try the below query and take care of those syntax errors which might come with you run directly.
    But the basic logic is correct. So add your tablename and try out the result.



    Select LineNo, Sum(Case status When NO then Sum(Manpower)/2 Else Sum(Manpower) END) as Summary FROM Table_Name
    Group By LineNo



    Thanks,
    Mani

  • #768978
    Hai Ram Prasad,
    You can have Group By LineNo and Status so that the records will be grouped based on the LineNo and Status and then you can segregate the results.

    Select LineNo, Status, Sum(Manpower) as Manpwer
    FROM Table_Name
    Group By LineNo, Status

    Hope it will be helpful to you.

    Regards,
    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)
    pawansoftit@gmail.com


  • Sign In to post your comments