将一列中相同的值分组,然后将值从另一列添加到一起

时间:2017-01-23 16:46:38

标签: sql-server-2012 sum

如何查询以下内容: 表命名标签:列名为:Job_Number,数量

Job_Number | Qty
-------------------------
10         |  1
12         |  2
12         |  2
10         |  3
11         |  22
12         |  1
10         |  5
12         |  4

我的结果看起来像

Job_Number | Total_Qty
-------------------------
10         |  9
11         |  22
12         |  9

1 个答案:

答案 0 :(得分:0)

基本聚合......

myFunction() {
  // Declare variables 
  var input, filter, table, tr, td, i;
  input = document.getElementById("myInput");
  filter = input.value.toUpperCase();
  table = document.getElementById("myTable");
  tr = table.getElementsByTagName("tr");

  // Loop through all table rows, and hide those who don't match the search query
  for (i = 0; i < tr.length; i++) {
    //Column 1
    td_1 = tr[i].getElementsByTagName("td")[0];
    //Column 2
    td_2 = tr[i].getElementsByTagName("td")[1];
    if (td_1 || td_2) {
      if (td_1.innerHTML.toUpperCase().indexOf(filter) > -1 || td_2.innerHTML.toUpperCase().indexOf(filter)> -1) {
        tr[i].style.display = "";
      } else {
        tr[i].style.display = "none";
      }
    } 
  }
}