asp+access 筛选后列求和问题

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:54:51
asp+access
表里有3个字段 a,b,c 都是备注型
c输入数值,a代表货品种类,b代表货品商家,c代表金额
a b c
苹果 甲 50
梨子 甲 40
桃子 甲 30
苹果 乙 60
梨子 乙 50
桃子 乙 20
开始设定了两个搜索条件1.按照种类搜索 2.按照商家搜索
无论按照那个条件搜索 都会把该类别(比如苹果类或者甲类)的数值求和
怎么写 给个提示?
这样可否:
sql="select a,b,sum(c) from 表名 group by a,b where"
if request("a")<>"" then sql=sql&"a like '%"&a&"%' and" '前一页取得要查询的a的值不为空
if request("b")<>"" then sql=sql&"a like '%"&b&"%' and"
if right(exec,5)="WHERE" then exec=left(exec,clng(len(exec))-5) '解决所有参数都为空的情况
if right(exec,3)="AND" then exec=left(exec,clng(len(exec))-3) '去掉参数最后的and

sql="select a,b,sum(c) from 表名"
if request("a")<>"" or request("b")<>"" then
sql = sql & " where "
if request("a")<>"" then sql=sql&"a like '%"&a&"%'" '前一页取得要查询的a的值不为空
if request("b")<>"" then
if request("a")<>"" then sql=sql&" and "
sql=sql&"b like '%"&b&"%'"
end if
end if
sql = sql & " group by a,b"