
select
(sum(q机)*45+sum(q管)*30+sum(q托)*25)
as
sumMoney
from
sales
也可以用以下按name和month求分类总和
select
name,month,(sum(q机)*45+sum(q管)*30+sum(q托)*25)
as
sumMoney
from
sales
group
by
name,month
在部件中选择ADODC控件添加到窗体上,或者在工程菜单中引用ADO对象都可以下面开始写代码(我以ADO对象为例):
dim con as new adodb.connection '声明一个数据连接对象变量,用于打开数据库
dim rs as new adodb.recordset '声明一个数据集对象变量,用于打开数据表
private sub form_load()'在窗体加载事件中,打开数据连接对象
con.open "Provider=Microsoft.Jet.OLEDB.4.0data source=AFC.mdbpersist security info=false"
text1.text=""
end sub
Private Sub command1_Click() '单击查询按钮事件,完成计算数据列的和
if rs.state<>adstateclosed then rs.close
rs.open "select 票价 from 数据表名",con,1,3
if rs.eof=false and rs.bof=false then
rs.movefirst
while not rs.eof
if text1.text="" then
text1.text=rs.fields("票价")
else
text1.text=cdbl(text1.text)+rs.fields("票价")
end if
rs.movenext
wend
end if
end sub
试试吧,全是手写的,所以格式需要你自己校正
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)