Mysql SQL语句

删除重复数据:


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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值