zoukankan      html  css  js  c++  java
  • 常用的sql

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

    -- 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
    -- 从最新的数据中取出 制作中的数据
  • 相关阅读:
    第九周周记
    第七周周记
    第三次作业第一题
    第五周周记
    《世界是数字的》读后感想
    第十周周记
    迷茫
    测试作业
    价值观作业
    作业二 感想
  • 原文地址:https://www.cnblogs.com/ctaixw/p/13358886.html
Copyright © 2011-2022 走看看