1樓:鬼火狼煙
你可以先用select * from user取出全部的資料。
然後取得rs的最大記錄數(,然後再隨機取出1到最大記錄數之間的隨機5個數(這步應該很簡單,不櫻盯緩用解釋如何做了吧呵呵),然後使用你隨機的5個數字之一脊模)就可以分別取出5條記錄來。這個辦法的則搏好處是你的主鍵id不需要是連續的,而絕大多數表都不是連續的呵呵。所以使用sql語句的where id=隨機數字的方法不是很安全。
2樓:幹濮魏鴻運
給你個我的思路吧:
點選按鈕後,提取此表的id列(假設有個id唯一標識主鍵列吧)的所有記錄放悉悄到乙個陣列a中,然後使用for迴圈和random()方法隨即提取睜液渣a陣列中的五個資料,放到另乙個陣列b中,例埋灶如:
for(int
i=0;1<5;i++)
randomronew
random(a的陣列長度減1);
b[i]=a[ro];
最後利用sql語句將符合此五個id的資料顯示出來,(注意sql可以用in會比較簡單)
mysql實現隨機獲取幾條資料的方法
3樓:網友
1.隨機讀取連續多條記錄。經過實踐,可以隨機讀取多條連續的資料記錄,裡頭取值的一般都是主鍵id來進行最大值、最小值的讀取:
select * from example_table as t1 join (select round(rand() select max(id) from example_table)-(select min(id) from example_table))+select min(id) from example_table)) as id) as t2 where >= order by limit 5;
2.隨機多條資料。以下兩種都是隨機讀取資料,查詢資料速度、隨機範圍都基本相差不大。
select * from example_table where id >= ((select max(id) from example_table)-(select min(id) from example_table)) rand() select min(id) from example_table) limit 5;
select * from example_table where id>=(select floor(rand() select max(id) from example_table)-(select min(id) from example_table)) select min(id) from example_table)))order by id limit 5;
C怎麼取出資料庫的記錄
把這段 sqldatareader dreader cmd.executereader 換成 sqldataadapter sda new sqldataadapter cmd datatable dt new datatable sda.fill dt return dt 這個返回的是存放資料的表...
資料庫管理系統能對資料庫中的資料進行查詢 插入 修改和刪除等操作,這種功能稱為
是操縱功能,即select,insert,update,delete屬於dml資料操縱語言。所以選d 以上為資料庫操作行為,屬於資料庫管理功能,因此選c 選d,資料操縱功能。原因如下 1 資料定義功能 資料描述語言 ddl data definition language,使用者可通過它來定義資料物...
vb怎麼讀取acceess資料庫中的資料並顯示在介面上
開啟vb程式,點檔案 新建工程 資料工程,在視窗新增一個command控制元件和一個datagrid控制元件。插入如下 private sub command1 click dim mycon as new adodb.connectiondim myrt as new adodb.recordse...