这是一个网站受访的统计列表ID  产品名  用户  时间
1    a       u1   1点
2    b       u1   2点
3    b       u2   3点
4    a       u3   4点
5    c       u2   5点
比如我想查询 产品a有的入口值是多少说是说产品a是哪些用户看的每个产品上边表的结果是2
U1 U3 第一个看的产品是a
查询 产品b 的结果=1U2    看的第一个产品是b

解决方案 »

  1.   

    ID  产品名  用户  时间 
    1    a      u1  2008-9-2 13:20:20
    2    b      u1  2008-9-2 13:21:20
    3    b      u2  2008-9-2 13:22:20 
    4    a      u3  2008-9-2 13:23:20 
    5    c      u2  2008-9-2 13:24:20 
    比如我想查询 产品a有的入口数是多少 入口数:说是说,每个用户看到的第一个产品.以后看到的产品都不算入口数. 这样就能统计出我的网店是因为哪个产品进来的上边表的结果是2 
    U1 U3 第一个看的产品是a 
    查询 产品b 的结果=1 U2    看的第一个产品是b 
      

  2.   

    select 产品名,count(*) as 入口数 from tb a where not exists (select 1 from tb where 用户=a.用户 and ID>a.ID) group by 产品名
      

  3.   

    select cp,count(*) as counts from abc a  where cp = (select  top 1 cp from abc where us=a.us  order by id) group by cp
    经测试.这个是对的
      

  4.   

    select cp,count(*) as counts from abc a  where cp = (select  top 1 cp from abc where us=a.us  order by id) group by cp select  top 1 cp from abc where us=a.us  order by id 这句查询.这用户看的第一个产品的名字..如果跟产品相同..说明是入品产品.