0

SQLのデータテーブルからすべての行の行の合計を取得することは可能ですか?このようなデータテーブルが1つあります

Date             col1           col2       col3
30/7/2012          5              2           3
31/7/2012          2              3           5
01/08/2012         2              4           1

しかし、私は1つの列名を作成することによってこのように達成したいと思います。

 Date            Total      col1           col2       col3
30/7/2012         10          5              2           3
31/7/2012         9           1              3           5
01/08/2012        7           2              4           1

出来ますか?はいの場合、同じように私を助けてください。

4

2 に答える 2

3

これを試して:

select Date,
       col1 + col2 + col3 as Total,
       col1, col2, col3
  from your_table;
于 2012-07-31T06:26:39.567 に答える
1

TotalのDataColumn.Expressionプロパティを使用してDataColumn、列の値を各行の他の列の値の合計として計算できます。

var totalColumn = new DataColumn("Total");
// Add your Total column to your DataTable.
dt.Columns.Add(totalColumn);
// The new column will be the second in the DataTable, like your diagram shows.
totalColumn.SetOrdinal(1);
// Use the sum of each row's Col1, Col2 and Col3 for the values in this column.
totalColumn.Expression = "[Col1] + [Col2] + [Col3]";
于 2012-07-31T07:00:00.823 に答える