查询最后一次出现的记录数量!怎样提取查询出来的结果在一个月内的总和?

来源:百度知道 编辑:UC知道 时间:2024/05/10 21:49:34
比方说每个姓名对应1个电话号码,而有的电话号码相同,怎样取出每个电话号码最后一次出现的记录!

日期可以自己写比方说从2008年1月1号到2008年1月2号,日期类型是日期型不是整形,下面的只是取出所有这个时间段的记录,rq1为初始时间,rq2为结束时间 (rq1和rq2是往里面输入的时间)
if request.form("submit2")<>"" then
rq1=request.form("rq1")
rq2=request.form("rq2")
sql="select 工号,count(工号) from tab1 where (受理时间 >#"&rq1&" 23:59:59# and 受理时间 <#"&rq2&" 23:59:59#) and not exists(select 1 from tab1 where 受理号码=a.受理号码 and 受理时间>a.受理时间) group by 工号 order by 工号"
call q(sql)
end if
这样是查询出来每天最后一次出现相同的记录工号数量,怎样查询出来这个月每个工号每天出来的数量,累加起来,查询出来每个月每个工号出来的总数量? 请各位指教!

SQL SERVER 的话,你可以用compute函数
ACCESS的话,你只能在网页里面做循环
sql="select 工号 tab1 where (受理时间 >#"&rq1&" 23:59:59# and 受理时间 <#"&rq2&" 23:59:59#) and not exists(select 1 from tab1 where 受理号码=a.受理号码 and 受理时间>a.受理时间) order by 工号"
dim c_gh,gh
if not gh=rs("工号") then
response.write(gh,c_gh)
gh=rs("工号")
c_gh=1
else
c_gh=c_gh+1
end if
大概是这么个思路

// sql server
select convert(varchar(7),时间,120),count(工号) from tablename group by convert(varchar(7),时间,120)

select convert(varchar(10),时间,120)count(工号) from tablename group by convert(varchar(10),时间,120)

// access
select month(时间),count(工号) from tablename group by month(时间)

select day(时间),count(工号) from tablename group by day(时间)

每天
select month(时间),day(时间),count(工号) from tablename group by 工号,month(时间),day(时间)
每月
select month(时间),day(时间),count(工号) from tablename group by 工号,mont