Postgres功能与选择

时间:2016-01-08 00:23:43

标签: postgresql

我想将此功能显示为:

var appModule = angular.module("appModule", ['ngRoute']);


appModule.fac   //This is me typing factory, but auto complete doesn't help

作为输入,只有年份,因为输出应返回select。 我试过make函数,但它不起作用。 有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我有一张如下表

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 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