Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2003
    Posts
    32

    Unanswered: how to calculate value from one table (database)

    hi,

    i have problem with this situation. i have one table which have listing item and qty for each item, so what i want to do is display all the distinct item with some parameter value and and sum the qty each item

    in my table on database it's look like this

    item | qty
    1. Pentium 10
    2. AMD Athlon 20
    3. Pentium 15


    then what i need to do with my asp is display like this

    item | qty
    1. Pentium 35
    2. AMD Athlon 20

    how i should code this in asp, because for display all it'work. so i'll hope you help me. it's appreciated if you give some other source code.

    thanks

  2. #2
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    Code:
    SELECT item, SUM(qty)AS 'total'
    from tableName
    GROUP BY item
    HAVING SUM(qty) > 0

  3. #3
    Join Date
    Mar 2003
    Posts
    32

    Question

    i think it works but how can we count the qty with WHERE statment

    code = "001"

    SELECT item, SUM(qty)AS 'total'
    from tableName
    GROUP BY item
    HAVING SUM(qty) > 0 WHERE id_item = '"&code&"'"


    it this code posssible or not

    tq

  4. #4
    Join Date
    Jan 2003
    Location
    Midwest
    Posts
    138
    This works in MSSQL not sure what database your using though.
    Code:
    SELECT t.id, t.item, 
    (SELECT SUM(qty) FROM tableName WHERE item = t.item) AS 'Total' 
    FROM tableName AS t 
    WHERE t.id = 001;

  5. #5
    Join Date
    Mar 2003
    Posts
    32

    Thumbs up

    thank you very much your code it's work, actually im using sql server 2000..


    much appreciated
    tq

Posting Permissions

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