Mysql每天执行计划,保留最新的10条数据,其余的删除 1.Mysql 保留最新的10条数据 sql语句: DELETE tb FROM tbname AS tb,( SELECT id FROM tbname ORDER BY id desc LIMIT 9,1 ) AS tmp WHERE tb.id<tmp.id 2.新建存储过程(Navicat中) CREATE PROCEDURE test() BEGIN DELETE tb FROM testdata AS tb,( SELECT…
方法:mysql取分组后最新的一条记录,下面两种方法.一种是先筛选 出最大和最新的时间,在连表查询.一种是先排序,然后在次分组查询(默认第一条),就是最新的一条数据了 #select * from t_assistant_article as a, (select max(base_id) as base_id, max(create_time) as create_time from t_assistant_article as b group by base_id ) as b where…
表tariff_info, 原始数据: 想要的结果:以start_time时间倒序排序, 以code分类, 查询每一类最新的一条记录 sql: SELECT a.* FROM TARIFF_INFO a, ( SELECT code, MAX (start_time) start_time FROM TARIFF_INFO GROUP BY code ) b WHERE a.start_time = b.start_time AND a.code = b.code ORDER BY a.code…
oracle中怎么查询各组中最新的一条记录呢?比如说现在有一个表中几条数据如下: 有两种写法:写法一:over partition by 分析函数 SELECT * FROM (select ID_,COMPANY_NAME,USAGE_RATE,DETECTION_RATE,ACCEPTABILITY_RATE,CREATE_TIME,MAX(CREATE_TIME) over(partition by COMPANY_NAME) as "atime" from SPEC_RATE_…