locked
need help to solve a problem RRS feed

  • Question

  • My problem is the following sittuation:

    I have this table in ACCESS database and i want help to get an SQL expression to solve the issue i explain:

    this is the table i have, with 2 columns:

    CODE               count

    0101                  5

    0101                  8

    0101                  7

    0305                  8

    0305                  6

    0305                  1

    So, what i want to do is to obtain the total of the count for each CODE

    Example: for the CODE 0101 i have 5+8+7 = 20

    So, i want to have an SQL expression that give me a table with the totals to each code

    maybe its not complicated, but i am an inniciate with SQL, can you please help me with that?

    Sunday, April 15, 2012 1:19 AM

Answers

  • select code, sum([Count]) as [Total Count] 
    from myTable GROUP BY [Code]


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Proposed as answer by Daniel_Steiner Sunday, April 15, 2012 8:58 AM
    • Marked as answer by joca_santos Sunday, April 15, 2012 9:27 PM
    Sunday, April 15, 2012 4:18 AM
  • Hi,

    Use Group by function http://msdn.microsoft.com/en-us/library/ms177673.aspx

    SELECT CODE, SUM([count])
    FROM tablename
    GROUP BY [CODE]

    I hope this is helpful.


    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid

    MyBlog

    • Marked as answer by joca_santos Sunday, April 15, 2012 9:27 PM
    Sunday, April 15, 2012 6:00 AM

All replies

  • select code, sum([Count]) as [Total Count] 
    from myTable GROUP BY [Code]


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog

    • Proposed as answer by Daniel_Steiner Sunday, April 15, 2012 8:58 AM
    • Marked as answer by joca_santos Sunday, April 15, 2012 9:27 PM
    Sunday, April 15, 2012 4:18 AM
  • Hi,

    Use Group by function http://msdn.microsoft.com/en-us/library/ms177673.aspx

    SELECT CODE, SUM([count])
    FROM tablename
    GROUP BY [CODE]

    I hope this is helpful.


    Please Mark it as Answered if it answered your question
    OR mark it as Helpful if it help you to solve your problem
    Elmozamil Elamir Hamid

    MyBlog

    • Marked as answer by joca_santos Sunday, April 15, 2012 9:27 PM
    Sunday, April 15, 2012 6:00 AM
  • as explained above you will need to use the GROUP BY statement and a SUM() function in your SELECT clause


    John

    http://knowledgy.org

    Sunday, April 15, 2012 5:56 PM
  • Thanks for your help

    It works


    joca_santos

    Sunday, April 15, 2012 9:27 PM