4

DB2随机抽样的SQL

 3 years ago
source link: https://www.lujun9972.win/blog/2020/04/10/db2%E9%9A%8F%E6%9C%BA%E6%8A%BD%E6%A0%B7%E7%9A%84sql/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
DB2随机抽样的SQL - 暗无天日

DB2随机抽样的SQL

其实就是活用rand函数.

比如从数据库中随机抽取100条记录,那么可以这样做

select * from $table order by rand() fetch first $limit rows only

不过如果数据量大,这个运算量可以想象那是相当感人了。

再比如从数据库中随机抽取1%的记录,那么可以这样做

select * from $table where int(rand()*100)=0
2020-04-10 2020-04-22 linux和它的小伙伴 DB2 数据库 lujun9972

Related Issues not found

Please contact @lujun9972 to initialize the comment

Generated by Emacs 27.x(Org mode 9.x)

Copyright © 2014 - 2021 lujun9972   -   Powered by EGO
Themed with emacs_love


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK