2016-05-13 72 views
-1

我需要得到像下面隨機整數的列表中...如何選擇隨機整數n個特定的總結

select FunctionNeeded(min_num, max_num, row count, sum of rows); 

我想要得到的結果是什麼

select FunctionNeeded(1, 10, 5, 30); 
----------------------------------------- 
5 
6 
7 
10 
2 

有什麼功能嗎?

任何方式的altanative也將不勝感激。

在此先感謝。

+0

你想傳遞給函數什麼參數?範圍?長度?等等? – Bohemian

+0

FunctionNeeded(min_num,max_num,行數,行數)。我編輯了這個問題。我很抱歉打擾。 – KIM

回答

0

你可以使用這樣的東西。我不明白30是什麼:

create function FunctionNeeded(
    value_from int, value_to int, 
    number_of_values int, something_else int) returns setof int as $$ 
select floor(random() * (1+$2-$1))::int + $1 
from generate_series(1,$3) 
$$ language sql;