a beginner question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • temptgan
    New Member
    • Oct 2006
    • 1

    #1

    a beginner question

    if i have a table like this:
    =========
    id units tag
    1 2 x
    1 3 x
    1 10 y
    2 5 x
    2 5 x
    2 2 x
    3 10 y
    3 3 x
    3 1 y
    =========

    basiclly the goal is to sum up all the units which has same tag for each id
    so that the output will be some thing like:
    ============
    id units tag
    1 5 x
    1 10 y
    2 12 x
    3 11 y
    3 3 x
    ============
    i am supose to use simple queries to do this job, but i just have no idea how to
    can any one give me an idea?

    thanks
  • xpcer
    New Member
    • Jul 2006
    • 51

    #2
    Originally posted by temptgan
    if i have a table like this:
    =========
    id units tag
    1 2 x
    1 3 x
    1 10 y
    2 5 x
    2 5 x
    2 2 x
    3 10 y
    3 3 x
    3 1 y
    =========

    basiclly the goal is to sum up all the units which has same tag for each id
    so that the output will be some thing like:
    ============
    id units tag
    1 5 x
    1 10 y
    2 12 x
    3 11 y
    3 3 x
    ============
    i am supose to use simple queries to do this job, but i just have no idea how to
    can any one give me an idea?

    thanks
    select id,sum(units) as units,tag from table_above
    group by id, tags

    Comment

    • xpcer
      New Member
      • Jul 2006
      • 51

      #3
      Originally posted by temptgan
      if i have a table like this:
      =========
      id units tag
      1 2 x
      1 3 x
      1 10 y
      2 5 x
      2 5 x
      2 2 x
      3 10 y
      3 3 x
      3 1 y
      =========

      basiclly the goal is to sum up all the units which has same tag for each id
      so that the output will be some thing like:
      ============
      id units tag
      1 5 x
      1 10 y
      2 12 x
      3 11 y
      3 3 x
      ============
      i am supose to use simple queries to do this job, but i just have no idea how to
      can any one give me an idea?

      thanks
      select id,sum(units) as units,tag from table_above
      group by id, tag

      Comment

      Working...