I need to select rows randomly. Ex : Let us assume, a table consists with 100 records ,but i need to get only 20 records from out of those 100 records and record selection will be in randomly.. how would i come out from it? I am using oracle as my db. any suggestion would help me greatly. Thanks in advance..
相关问题
- how to get selected text from iframe with javascri
- Can I skip certificate verification oracle utl_htt
- Unity - Get Random Color at Spawning
- how to calculate sum time with data type char in o
- keeping one connection to DB or opening closing pe
相关文章
- node连接远程oracle报错
- oracle 11g expdp导出作业调用失败,提示丢包。
- 执行一复杂的SQL语句效率高,还是执行多少简单的语句效率高
- Oracle equivalent of PostgreSQL INSERT…RETURNING *
- why 48 bit seed in util Random class?
- Difference between FOR UPDATE OF and FOR UPDATE
- Need help generating discrete random numbers from
- Oracle USING clause best practice
To randomly select 20 rows I think you'd be better off selecting the lot of them randomly ordered and selecting the first 20 of that set.
Something like:
Best used for small tables to avoid selecting large chunks of data only to discard most of it.
This is more efficient as it doesn't need to sort the Table.
SAMPLE() is not guaranteed to give you exactly 20 rows, but might be suitable (and may perform significantly better than a full query + sort-by-random for large tables):
Note: the
20
here is an approximate percentage, not the number of rows desired. In this case, since you have 100 rows, to get approximately 20 rows you ask for a 20% sample.