根据ID总结GridView列 [英] Sum up GridView column based on ID
问题描述
Hello Friends我需要对GridView的元素进行分组,如下所示。
我需要根据其ID来总结价格
GridView中的数据
ID1 ----- ID2 -----价格
----------------------
1 ------- 1 ------- 100
2 ------- 1 ------- 200 >
3 ------- 1 ------- 150
4 ------- 2 ------- 120 >
5 ------- 2 ------- 160
6 ------- 3 ------- 100 >
7 ------- 3 ------- 200
我想将这些数据分组如下所示并保存在数据表中,以便我可以将它传递给我的数据库
ID2 -----价格
------- ------
1 ------- 450
2 ------- 270
3- ------ 300
我该怎么做?
提前致谢
Hello Friends I need to group the elements of GridView as shown below.
I need to sum up the price according to its ID's
Data in GridView
ID1-----ID2-----Price
----------------------
1-------1-------100
2-------1-------200
3-------1-------150
4-------2-------120
5-------2-------160
6-------3-------100
7-------3-------200
I want to group this data as shown below and save it in a datatable so that I can pass it to my Database
ID2-----Price
-------------
1-------450
2-------270
3-------300
How do I do this?
Thanks in advance
推荐答案
Select ID2, SUM(Price) from table_name group by ID2 asc
这篇关于根据ID总结GridView列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!