删除重复数据:
delete tab_played_games a from tab_played_games a,
(select *,min(id) from tab_played_games T where T.GAME_ID = 3 group by T.user_ID having count(1) > 1
) as b
where a.USER_ID = b.USER_ID and a.id > b.id;
delete tab_played_games a from tab_played_games a,
(
select *,min(id) from tab_played_games T group by T.user_ID having count(1) > 1
) as b
where a.USER_ID = b.USER_ID
and a.GAME_ID = b.GAME_ID
and a.id > b.id;
分组查询,限定分组的大小:
SELECT T02.ID userid
,T02.USER_CODE usercode
,T02.NICKNAME nickname
,T02.SEX sex
,T02.AGE age
,T02.CITY city
,T02.HEAD_IMG headimg
,T02.IMG_URL img
,T04.GAME_ID
,T03.GAME_IMG_URL
FROM tab_friend T01
,tab_user T02
,tab_game T03
, (SELECT *
FROM tab_played_games A
WHERE #{size}>(select count(*) from tab_played_games B where B.User_ID=A.User_ID and B.PLAY_DATE>A.PLAY_DATE)
ORDER BY USER_ID asc , A.PLAY_DATE desc) T04
WHERE T01.FRIEND_ID = T02.ID
AND T04.USER_ID = T01.FRIEND_ID
AND T01.USER_ID =#{userid}
AND T03.ID = T04.GAME_ID
ORDER BY T01.DATE desc, T04.PLAY_DATE desc