如何 select 来自 Pervasive PSQL 的随机行 table
How to select a random row from a Pervasive PSQL table
在 Pervasive PSQL 中(具体来说),使用 sql select 语句,你如何 select 来自 table 的随机行没有数字 ID?
这似乎对我使用 PSQL v11.30 有用。
create table chartest (f1 char (10), f2 char(10), f3 char(10));
insert into chartest values ('a','a','a');
insert into chartest values ('b','b','b');
insert into chartest values ('c','c','c');
insert into chartest values ('d','d','d');
insert into chartest values ('e','e','e');
insert into chartest values ('f','f','f');
select top 1 * from chartest order by newid()
我 运行 几次并得到:
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
e e e
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
c c c
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
b b b
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
f f f
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
在 Pervasive PSQL 中(具体来说),使用 sql select 语句,你如何 select 来自 table 的随机行没有数字 ID?
这似乎对我使用 PSQL v11.30 有用。
create table chartest (f1 char (10), f2 char(10), f3 char(10));
insert into chartest values ('a','a','a');
insert into chartest values ('b','b','b');
insert into chartest values ('c','c','c');
insert into chartest values ('d','d','d');
insert into chartest values ('e','e','e');
insert into chartest values ('f','f','f');
select top 1 * from chartest order by newid()
我 运行 几次并得到:
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
e e e
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
c c c
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
b b b
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>
<<<<<<<<<<<<<<<<<<<<<<<<
f1 f2 f3
========== ========== ==========
f f f
1 row was affected.
>>>>>>>>>>>>>>>>>>>>>>>>