1)使用join 和 rand() 耗时 0.009 SELECT * FROM `t_topic` AS t1 JOIN ( SELECT ROUND( RAND() * ( (SELECT MAX(id) FROM `t_topic`) - (SELECT MIN(id) FROM `t_topic`) ) + (SELECT MIN(id) FROM `t_topic`) ) AS id ) AS t2 WHERE t1.id >= t2.id ORDER BY t1.id LIMIT ;…
在sql server中,取数据中前10条语句,我们可以用top 10 这样语句,但是oracle就没有这个函数,接下来介绍它们之间的区别 1.sql server 取前10语句和随机10条的语法 --测试表数据-- select * from BdsPaperItem --查询测试表的前10条语句-- * from BdsPaperItem order by Uid asc --随机查询测试表10条语句-- * from BdsPaperItem order by NEWID() 结果实例:…
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…