在日常的测试工作中,有时候我们需要随机选取数据库中的一行数据,以下是各个数据库中实现该功能的方法。
提供给大家作为参考:
MYSQL:
SELECT column FROM table ORDER BY RAND() LIMIT 1
PostgreSQL:
SELECT column FROM table ORDER BY RANDOM() LIMIT 1
SQL Server :
SELECT TOP 1 column FROM table ORDER BY NEWID()
Oracle:
SELECT column FROM ( SELECT column FROM table ORDER BY dbms_random.value ) WHERE rownum = 1
SELECT column, RAND() as IDX FROM table yf_terminology_ORDER BY@#@#@#ORDER BY_yf_terminology IDX FETCH FIRST 1 ROWS ONLY