Postgresql 带select的Postgres函数
我想显示以下功能:Postgresql 带select的Postgres函数,postgresql,Postgresql,我想显示以下功能: select LoanId, BookId ,(OutDate-InDate)*0.3 as money, OutDate-InDate days from loans where (OutDate-InDate)> 30 and OutDate::varchar(4)='2000'; 作为输入只有一年,作为输出应该返回select。 我尝试了make函数,但它不起作用。 有什么想法吗?我有一张像下面这样的桌子 create table loan(loanid in
select LoanId, BookId ,(OutDate-InDate)*0.3 as money, OutDate-InDate days
from loans
where (OutDate-InDate)> 30 and OutDate::varchar(4)='2000';
作为输入只有一年,作为输出应该返回select。
我尝试了make函数,但它不起作用。
有什么想法吗?我有一张像下面这样的桌子
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\u LOAN\u DET('2015')
loanid bookid money days
------ ------ ----- ----
1 2 18.3 61
请分享您的代码,并准确解释哪些代码不起作用。请阅读以下内容,并在问题中添加更多信息,以便我们提供帮助!我试着读懂你的心思以便回答你的问题。。。。但它不起作用。有什么想法吗?