select ID,type,rkno,mount,date from table1 得到下图的结果:如果要得到同一机种数量和的结果(ETC56-605N总计为22=4+12+6),其余项不变,求这个sum的写法。

解决方案 »

  1.   

    这样就好了:
    select ID,type,rkno,sum(mount),date from table1 group by type
      

  2.   


    这样不行,一个type可能对应多个rkno,如果这么写,rkno的信息就不全了。
      

  3.   

    select ID,type,group_concat(rkno),sum(mount),date from table1 group by type;
    这样可以不
      

  4.   

    select ID,type,rkno,mount,date,(select sum(mount) from table1 where a.type=type) from table1 a
      

  5.   

    这些列能用一起合并到一行的话 可以用group_concat 函数。
    要是保持原有的样子,就再家一个列,把这个sum值带过去(join)
      

  6.   

    你的SQL语句,结果是什么,贴 出来
      

  7.   

    select ID,type,rkno,mount,date,(select sum(mount) from `rk_confirm` where a.type=type) from `rk_confirm` a
      

  8.   


    按照你的写法得出来的和1楼的图片结果一样。我需要机种对应数量那一栏同type的值的相加结果,格式和图中效果类似。是不是写法有问题?我在分析查询器里试试。
      

  9.   

    select ID,type,rkno,sum(mount),date 
    from table1 group by type,rkno;