重复时汇总记录 [英] Sum a record when duplicate

查看:36
本文介绍了重复时汇总记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找这个问题的答案,但找不到我真正想要的!所以我不得不在这里问..

I've searched for an answer to this all over but couldn't find what i'm really looking for! so i had to ask here..

我不知道如何解释,但这里有一个表格:

i don't know how to explain this but here is a table :

  Date          BL          Client  Design      Ref1    Ref2    Ref3    Qte
  14/01/2013    13011401    A       VT          VT1     JAUNE   XL      3
  14/01/2013    13011402    B       VT          VT2     GRIS    L       30
  16/01/2013    13011601    D       VT          VT1     GRIS    L       10
  16/01/2013    13011602    C       VT          VT2     GRIS    L       32
  19/01/2013    13011903    F       VT          VT2     JAUNE   L       15

我正在寻找可能如下所示的结果:

i'm looking for a result that could look like the following:

  Date          BL          Client  Design      Ref1    Ref2    Ref3    Qte
  14/01/2013    13011401    A       VT          VT1     JAUNE   XL      3
  14/01/2013    13011402    B       VT          VT2     GRIS    L       62
  16/01/2013    13011601    D       VT          VT1     GRIS    L       10
  19/01/2013    13011903    F       VT          VT2     JAUNE   L       15

edit: sum Qte 如果有重复 (Design,Ref1, Ref2, Ref3)

edit: sum Qte if there is a duplicate (Design,Ref1, Ref2, Ref3)

不知道这是否可行,但我会感谢您的帮助!

don't know if this is possible but i would appreciate your help!

推荐答案

table : mytable

  col1          col2       Col3     col4    col5    col7    col8    col9
  14/01/2013    13011401    A       VT      VT1     JAUNE   XL      3
  14/01/2013    13011402    B       VT      VT2     GRIS    L       30
  16/01/2013    13011601    D       VT      VT1     GRIS    L       10
  16/01/2013    13011602    C       VT      VT2     GRIS    L       32
  19/01/2013    13011903    F       VT      VT2     JAUNE   L       15

我的理解是你想要在 col4,col5,col7,col8 的基础上进行复制,你可以这样做

What I understood is that You want duplicate on the basis of col4,col5,col7,col8 for this you can do like

SELECT col1,col2,Col3,col4,col5,col7,col8,SUM(col9)
FROM mytable
GROUP BY col4,col5,col7,col8;

在这个组中,其他字段总是返回第一行

In this group by will always return first row for other fields

这篇关于重复时汇总记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆