表格字段结构如下:  ID  Name  Value
表中存在相同ID的多笔记录,现在是希望能够查询出 所有 相同ID的 Value数的 求和谢谢大家!

解决方案 »

  1.   

    table : test
    id name value
    0  xixi  10
    1  hehe  11
    1  hehe  13
    2  wuwu  9
    0  xixi  100需要的结果如下:
    0  xixi  110
    1  hehe  24
    2  wuwu  9谢谢大家!
      

  2.   

    select id,name,sum(value) from test group by id,name
      

  3.   

    谢谢ACMain_CHM的指点现在还有个需求,就是在上面的基础上,还有另外一张表
    table : context
    id desc
    0  one
    0  two
    1  oneone
    2  twotwo需要能够根据上面数据排序后的id,检索出context表格中的desc信息
      

  4.   

    需要的结果如下:
    0 xixi one 110
    0 xixi two 110
    1 hehe oneone 24
    2 wuwu twotwo 9
      

  5.   

    恩,谢谢ACMAIN_CHM提醒,下次改正,刚开始学SQL 呵呵,还不熟悉
      

  6.   

    select c.*,b.value from context c 
    left join 
             (select id,name,sum(value) value from test group by id,name) t 
    on c.id = t.id; 
      

  7.   

    select b.id,b.name,c.desc,b.value value from context c 
    left join 
      (select id,name,sum(value) value from test group by id,name) t 
    on c.id = t.id;