在h2 dbms我有一个表
CREATE TABLE sometable
( ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
somevalue INTEGER)
和一些数据
INSERT INTO sometable(somevalue)
VALUES (1), (2), (3), (4), (5);
当SELECT somevalue FROM sometable LIMIT 1 OFFSET 2
有效时。 为什么如果我想选择随机行
SELECT somevalue FROM sometable LIMIT 1 OFFSET (RANDOM()*4)
不起作用?
答案 0 :(得分:1)
您可以这样做:
create table test(
id bigint auto_increment primary key,
name varchar(255));
insert into test
select x, 'Hello ' || x from system_range(50, 1200);
select * from test t, system_range(1, 100) range
where t.id = x * (select max(id)-min(id) from test) / 100 +
(select min(id) from test);