SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Adding up

  1. #1
    SitePoint Enthusiast Bloobird's Avatar
    Join Date
    Jan 2005
    Location
    Wales UK
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding up

    I have a table which looks something like this

    product_name Barcode Quantity
    --------------------------------------------
    product 1---- 12345---- 12
    product 1---- 4568---- 15
    product 1---- 8955---- 14
    product 2---- 8954---- 11
    product 2---- 8957---- 1

    As you can see each batch of products has a different barcode. However I would like to be able to find out how many of each product is in stock without having to add up each individual quantity.
    EG I would like it add up all of product 2 so I can see that 12 are in stock.
    Im using PHP for this and was wondering if mysql has a funtion which will do this quickly.

    Thanks

  2. #2
    Woof! Woof! elel1138's Avatar
    Join Date
    Apr 2004
    Location
    Warsaw, Poland
    Posts
    202
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
      SELECT sum(Quantity) FROM Products GROUP BY product_name;
    Leszek Leszczyński
    www.hazelsoft.com
    --- Real programmers don't document. If it was hard to write,
    it should be hard to understand. ---

  3. #3
    SitePoint Enthusiast Bloobird's Avatar
    Join Date
    Jan 2005
    Location
    Wales UK
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •