我有一個表像下面
create table loan(loanid int,bookid int,outdate date,indate date);
像這樣
insert into loan values(1,2,'01-12-2015','01-10-2015'),(1,2,'01-01-2016','08-01-2016');
一些數據,我用下面的select查詢
select loanid,bookid,(outdate-indate)*0.3 as "money",outdate-indate as "days"
from loan
where (OutDate-InDate)> 30 and extract(year from outdate)='2015'
loanid bookid money days
------ ------ ----- ----
1 2 18.3 61
現在我有一個函數做的工作是
create or replace function FN_LOAN_DET(in_year text)
returns table (loanid int,bookid int,money numeric,days int)
as
$$
select loanid,bookid,(outdate-indate)*0.3 as "money",outdate-indate as "days"
from loan
where (OutDate-InDate)> 30 and extract(year from outdate)=$1
$$
language sql
當我打電話select * from FN_LOAN_DET('2015')
我會得到
loanid bookid money days
------ ------ ----- ----
1 2 18.3 61
請分享您的代碼,並解釋到底是什麼沒有在那裏工作。 – Mureinik
請閱讀以下內容並在問題中添加更多信息,以便我們提供幫助! https://stackoverflow.com/help/mcve – Ross
我試圖讀你的思想,所以我可以回答你的問題....但它沒有奏效。任何想法? –