我有一个表像下面
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
我试图读你的思想,所以我可以回答你的问题....但它没有奏效。任何想法? –