ID ------------主键
EventID ------活动ID
JionDateTime, ------参加活动的时间
UserID, -------谁参加的
Platform_ID--------- 这个是无关的一个字段(不用管)
我要查询一个人UserID参加的所有活动,57,64,62(应为他可能重复参加(所以有多个57,62),
因此我只去其中一个就可以,用最大的一个时间JionDateTime来表示.查询userID=2的情况
最终结果 如eventID userID JionDateTime Platform_ID
57          2          最大时间          1111
72          2          最大时间          22222
58          2          最大时间          11311

解决方案 »

  1.   

    select * from tablename a where exists
    (select 1from tablename b join a on a.enventid=b.enventid and a.userid=b.userid and
    a.jiondatetime<b.jiondatetime)
      

  2.   

    难道是
    select eventid,max(jiondatetime),userid from userjoinhistoryset group by eventid,userid
      

  3.   

    SELECT EventID, UserID, MAX(JionDateTime) AS JionDateTime
    FROM UserJoinHistorySet
    GROUP BY UserID, EventID
    HAVING (UserID = 2)
      

  4.   


    select *
    from tb t
    where not exists (select 1 from tb where userID = t.userID and eventID = t.eventID and JoinDateTime > t.JoinDateTime)
      

  5.   

    Platform_ID我还在为这一列考虑呢~~
      

  6.   

    select * from tb a
    where not exists
    (select 1 from tb b where a.UserID=b.UserID 
       and a.EventID=b.EventID 
      and b.JionDateTime>a.JionDateTime)恭喜,接分