Question: I am currently working with oracle SQL with a database with different metrics. However, what I'm looking for is an arithmetic combination of the different metrics. All of this information is currently in one table.

Ideally I would create a new metric through basic math of currently stored data. I would not need any of the current output, just it's combination into the new metric.

I don't know how to limit it to know that for each specific building/date to only combine metric Z,X and Y.

Current Output: 

`Date Building Metric Performance`  

`--------------------------------------------`  

`12/1/19 A Z 1`  

`12/1/19 A Y 2`  

`12/1/19 A X 3`

Desired Output (functionally):  

`12/1/19 A W =(1+2)/3` 

Thank you!

Answer: 
What about as follows?

```
line(N) :-
  foreach(between(1, N, _), write('*')),
  nl.

star(1) :-
  line(1).

star(N) :-
  line(N),
  NM1 is N-1,
  star(NM1),
  line(N).

```

Calling `star(N)`.
This should work:

```
%this is the main function you want to call
star(N) :-
  starl(N),
  starr(1,N).

% counts down from n to zero and 
% writes according amount of stars
starl(0):- !.
starl(N):-
  write_n_times("*", N),
  Nm is N-1,
  starl(Nm).

% counts up from X to Np and 
% writes according amount of stars
starr(N, N):- write_n_times("*", N), !.
starr(X, Np):-
  write_n_times("*", X),
  Xp is X+1,
  starr(Xp, Np).

% writes X for I times and makes then a new line
write_n_times(_,0) :- nl, !.
write_n_times(X,I) :-
  write(X),
  Im is I - 1,
  write_n_times(X,Im).

```