首页 > 数据库技术 > 详细

常用的sql

时间:2020-07-22 10:57:15      阅读:86      评论:0      收藏:0      [点我收藏+]

数据重复了,只需要其中一条

-- id 重复了,取出其中一条
SELECT id,member_seq,point,gmt_create
FROM XXXX
WHERE 
            and gmt_create > "2020-07-20 00:00:00"
    and gmt_create < "2020-07-26 23:59:59"
    AND point > 0
GROUP BY id,member_seq,point,gmt_create
-- id 重复了,取出其中一条
 
 
数据没有重复,取出最早的一条数据
-- 从最新的数据中取出 制作中的数据
SELECT id,user_id,material_id,status FROM (
  -- https://blog.csdn.net/qq_37111953/article/details/80916820
  -- 取出每个用户最新的一条用户物料数据
  select a.id,a.user_id,a.material_id,a.status
  from (
      select * from xxxxxx
      where activity_id = n and ds = 20100622
  ) a
  left join (
      select * from xxxxxx
      where activity_id = n and ds = 20100622
  ) b
  on a.user_id=b.user_id and a.gmt_create<b.gmt_create
  group by a.id,a.user_id,a.material_id,a.status
  having count(b.id)<1
  -- 取出每个用户最新的一条用户物料数据
)as last_record_all
where status = 1
-- 从最新的数据中取出 制作中的数据

常用的sql

原文:https://www.cnblogs.com/ctaixw/p/13358886.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!