select product as 产品, sum(quantity) as 数量 from ( select '产品1' as product, 2 as quantity from dual union all select '产品2', 3 union all select '产品3', 4 union all select '产品2', 2 union all select '产品1', 6 union all select '产品4', 7 ) group by product--结果 产品 数量 ----- ---------------------- 产品3 4 产品1 8 产品2 5 产品4 7 打开数据源,ADODC 绑定DATAGRID 请楼主自己写吧,我快三年没写过VB代码了。
SQL SERVER语法还有一种写法COMPUTE BYSELECT 产品,数量 from tableName order by 产品 compute SUM(数量) by 产品
select product as 产品, sum(quantity) as 数量 from (
select '产品1' as product, 2 as quantity from dual
union all
select '产品2', 3
union all
select '产品3', 4
union all
select '产品2', 2
union all
select '产品1', 6
union all
select '产品4', 7
)
group by product--结果
产品 数量
----- ----------------------
产品3 4
产品1 8
产品2 5
产品4 7 打开数据源,ADODC
绑定DATAGRID
请楼主自己写吧,我快三年没写过VB代码了。
order by 产品
compute SUM(数量) by 产品