Query Help

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shailja
    New Member
    • Feb 2007
    • 123

    Query Help

    Hello,

    My table has following data.

    ItemId BatchNo Qty

    1 B101 100
    1 B102 250
    1 B101 50
    2 B102 150
    2 B103 200
    2 B103 100

    Now I want to fire the query which gives me following output:

    ItemId BatchNo Qty
    1 B101 150
    B102 250

    2 B102 150
    B103 300

    Kindly help me if u know. Thanks
  • frozenmist
    Recognized Expert New Member
    • May 2007
    • 179

    #2
    Hi Shailja,
    Thanks for your posting on this forum.
    But when you request for help on a query , as per the posting guidelines, you are expected to post the code that you have tried out.
    But I can help you by giving a hint that may help you write the query.

    What you need is the SUM of qty categorised by ItemID and BatchNo..
    Convert the above statement into a query and you will get it.
    Do try out the query and revert if any more problems.

    Cheers

    Comment

    • Shailja
      New Member
      • Feb 2007
      • 123

      #3
      Originally posted by frozenmist
      Hi Shailja,
      Thanks for your posting on this forum.
      But when you request for help on a query , as per the posting guidelines, you are expected to post the code that you have tried out.
      But I can help you by giving a hint that may help you write the query.

      What you need is the SUM of qty categorised by ItemID and BatchNo..
      Convert the above statement into a query and you will get it.
      Do try out the query and revert if any more problems.

      Cheers

      Hi, I know query like this:
      SELECT SUM(Qty) FROM table GROUP BY ItemId, BatchNo

      But I want to display batch also. I m not getting batch. Request u to send me answer if u know.

      Thanks

      Comment

      • frozenmist
        Recognized Expert New Member
        • May 2007
        • 179

        #4
        Originally posted by Shailja
        Hi, I know query like this:
        SELECT SUM(Qty) FROM table GROUP BY ItemId, BatchNo

        But I want to display batch also. I m not getting batch. Request u to send me answer if u know.

        Thanks
        Hi,

        To display batch,just give batchno in the select.
        [code=sql]
        SELECT ItemID,BatchNo, SUM(Qty) FROM table GROUP BY ItemId, BatchNo

        [/code]
        It should work.

        Cheers

        Comment

        Working...