表:hy
字段: hy visittime
小李 2019-1-01 12:00:01
小沈 2019-1-01 13:02:21
小李 2019-3-01 22:00:01
小沈 2019-1-01 08:02:21
小李 2019-1-01 16:31:01
小沈 2019-1-01 11:12:21
小李 2019-3-01 02:30:01
小沈 2019-1-01 18:02:21
希望统计出的机构
用户 平均访问相隔时间
小李 30天12小时
小沈 10天12小时
请问兄台这个sql 怎么写呢,用的access
access似乎不支持子查询嵌套,那么没法搞,只能循环
别的数据库可以,参考思路 https://blog.csdn.net/zhengun/article/details/84915199
在mssql 里可以采用 如下语句:
select hy,avg(visittime1-visittime) avgtime from(
select hy,visittime ,(select top 1 visittime from hy b where b.hy=a.hy and b.visittime >a.visittime order by visittime ) visittime1 from
hy ) ahy where not visittime1 is null group by hy
参考,一下。