1. cacol89
  2. YADI

Source

YADI / test / integration / payment.datalog

%%%%%%%%%%%%%%%%%
% Whole-table aggregates 
%%%%%%%%%%%%%%%%%

Total(sum(p)) :- Payment(_,_,p,_).
?- Total(sp).
/

Stats(sum(p),max(p),min(p),avg(p),count(p)) :- Payment(_,_,p,_).
?- Stats(x,y,z,v,w).
/

Harry_stats(sum(p),max(p),min(p),avg(p),count(p)) :- Payment(x,_,p,_), Person(x,'Harry').
?- Harry_stats(x,y,z,v,w).
/

%%%%%%%%%%%%%%%%%
% Groupings
%%%%%%%%%%%%%%%%%

Person_stats(name,sum(a),max(a),min(a),avg(a),count(a)) :- Person(id,name), Payment(id,_,a,_).
?- Person_stats(n,s,mx,mn,av,cnt).
/

Person_service_sum(p_name,s_name,sum(amount)) :- Person(p_id,p_name), Service(s_id,s_name), Payment(p_id,s_id,amount,_).
?- Person_service_sum(p,s,t).
/

Payment_count(pid,count(pid)) :- Payment(pid,_,_,_).
?- Payment_count(x,y).
/

%Aggregates on two different vars
Q(day,min(pid),max(sid)) :- Payment(pid,sid,_,day).
?-Q(x,y,z).
/

%%%%%%%%%%%%%%%%%
% Non-supported aggregates
%%%%%%%%%%%%%%%%%

Prod(prod(p)) :- Payment(_,_,p,_).
?- Prod(pp).
/

%%%%%%%%%%%%%%%%%
% Aggregates in goals (not allowed)
%%%%%%%%%%%%%%%%%

Q(x,y) :- Person(x,avg(y)).
?- Q(x,y).
/



%Total(p,sum(x)) :- Person(pid,p), Payment(a,_,x,_).
%?- Total(x,y).
%/
%
%Total(p,sum(x)) :- Person(pid,p), Payment(a,_,x,_), sum(x) < 100.
%?- Total(x,y).
%/
%
%Total(p,x) :- Person(pid,p), Payment(a,_,x,_), sum(x) < 100.
%?- Total(x,y).
%/