mysql: select * from table order by id DESC limit 1 oracle: select * from emp where id in (select max(id) from emp); 实例: mysql> use weifeng; Database changed mysql> \G; *************************** . row *************************** bloggerId: likeNum…
从数据表中随机抽取n条数据有哪几种方法(join实现可以先查数据然后再拼接) 一.总结 一句话总结:最好的是这个:"SELECT * FROM table WHERE id >= ((SELECT MAX(id) FROM table)-(SELECT MIN(id) FROM table)) * RAND() + (SELECT MIN(id) FROM table) LIMIT n"; 1.thinkphp里面没有封装mysql中的Rand()方法,如何在thinkphp实…
目录 postgresql如何从表中高效的随机获取一条记录 随机获取一条记录random() 改写1 改写2 改写3 对比 注意 结语 postgresql如何从表中高效的随机获取一条记录 select C_BH from db_scld.t_scld_cprscjl order by `random()` LIMIT 1; select c_jdrybm from db_scld.t_jdry where c_bmbm = v_scdd and c_sfyx ='1' and c_ryzszt…
为了性能考虑,在阅读之前提醒大家,如果有子查询,子查询查询到的数据最好不要超过总数据量的30%. 查询有重复数据的记录 select * from F group by a,b,c,d having count(*)>1 select distinct * into #Tmp from tableName drop table tableName select * into tableName from #Tmp drop table #Tmp SQL删除重复数据方法 例如: id name…
创建测试用表: CREATE OR REPLACE VIEW V AS SELECT 'a' AS c FROM dual UNION ALL SELECT 'b' AS c FROM dual UNION ALL SELECT 'c' AS c FROM dual UNION ALL SELECT 'd' AS c FROM dual UNION ALL SELECT 'e' AS c FROM dual; SELECT * FROM v; 查询语句如下: SELECT c FROM (SEL…
Oracle: select * from (select * from tableName order by dbms_random.value) where rownum < N MS SQLServer: select top N * from tableName order by newid() My SQL: select * from tableName order by rand() limit N 原文:https://blog.csdn.net/senton/article/d…
oracle 中随机取一条记录的两种方法 V_COUNT INT:=0; V_NUM INT :=0; 1:TBL_MYTABLE 表中要有一个值连续且唯一的列FID BEGIN SELECT COUNT(*) INTO V_COUNT FROM TBL_MYTABLE; SELECT TRUNC(DBMS_RADOM.VALUE(1,V_COUNT+1)) INTO V_NUM FROM DUAL; SELECT * FROM TBL_MYTABLE T WHERE T.FID=V_NUM;…
SELECT t1.id,title,extName,cover,url FROM shop_articles AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM shop_articles)-(SELECT MIN(id) FROM shop_articles))+(SELECT MIN(id) FROM shop_articles)) AS id) AS t2 WHERE t1.id >= t2.id and type=_type…
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; //引入MySQL using MySql.Data.MySqlClient; using System.Data.SqlClien…