· 6 years ago · Jun 21, 2019, 11:58 AM
1CREATE TABLE
2IF NOT EXISTS test_tbl(
3 id INTEGER);
4INSERT INTO test_tbl
5VALUES (10),
6 (13),
7 (14),
8 (16),
9 (18),
10 (20);
11-------------------------------
12SELECT * FROM test_tbl;
13
14-------------------------------
15SELECT COALESCE(tmp.id, 20) AS classification_id
16FROM (
17 SELECT tt.id,
18 row_number() over(
19 ORDER BY tt.id) AS row_num
20 FROM test_tbl tt
21 ) tmp
22WHERE tmp.row_num =floor(random() * 10);