使用人数统计的SQL - MS-SQL Server / 疑难问题
SQL code:
create table #tb1(ip nvarchar(20),date datetime)
insert into #tb1
select '10.110.120.114','2010-04-01 03:57:49' union all
select '10.119.123.130','2010-04-01 04:01:22' union all
select '10.110.120.114','2010-04-01 04:04:51' union all
select '10.110.120.114','2010-04-01 04:11:42' union all
select '10.128.130.110','2010-04-01 04:04:51' union all
select '10.110.120.114','2010-04-01 06:48:42' union all
select '10.110.120.114','2010-04-01 06:57:45' union all
求实际使用人数.
以第一次出现的IP为准(group by IP),半小时内的都当做他一直在使用,半小时后出现的才算第二次使用。
以10.110.120.114举例,第一次是 03:57:49,此后半小时内出现的 04:04:51\04:11:42就不做统计了.(03:57:49)的半小时后最近的一个也就是 06:48:42,用它再做起点,06:57:45就又不统计……以此类推
求个IP实用的次数
结果应该是这样的
ip counts
-------------- -----------
10.110.120.114 2
10.119.123.130 1
10.128.130.110 1
SQL code:
create table #tb1(ip nvarchar(20),date datetime)
insert into #tb1
select '10.110.120.114','2010-04-01 03:57:49' union all
select '10.119.123.130','2010-04-01 04:01:22' union all
select '10.110.120.114','2010-04-01 04:04:51' union all
select '10.110.120.114','2010-04-01 04:11:42
相关问答:
tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
通过NAME字段条件查询一个数据表,假设我有100个姓名,有以下两个方法,
方法1:
把100个Name 组成一个SQL语句,比如 Select * from tmp_table where Name='张三' or Name ='李四' Or ...Or Name='第一百个姓名'
......