1

Topic: I ask to prompt how to obtain the data for last period

There are contracts on which there is a profit, but the contract formed on the basis of another for a long time closed on which too there was a profit.
The profit lies in the table of charges Summs
Id, Date, Sum, Id_Dog
1, 1/1/2010, 100, 1233
2, 1/1/2011, 200, 1233
3, 2/2/2012, 399, 1332
Contracts lie in the table with contracts doggs
Id_dog, d_start, d_end, Parent_dog
1233, 1/1/2000, 1/1/2012, NULL
1332, 1/2/2012, NULL, 1233
1300, 1/1/2000, 1/1/2012, NULL
The task: to obtain as a result of request the data and under the current contract, and on the previous.
I do so:

select sum (sum), id_dog from summs join doggs using (id_dog)
where parent_dog is not null

But I do not understand, how it is possible to tighten also the total from the previous contract...
There was a thought to make through WITH, but do not understand how to connect through, let us assume, LAG\LEAD.
Prompt, please

2

Re: I ask to prompt how to obtain the data for last period

Goose, lobster and ;
On on  to it , or on  I eat (a little, it is more 1)
....
stax

3

Re: I ask to prompt how to obtain the data for last period

Goose, lobster and ;
group by CONNECT_BY_ROOT
Stax;
Instead of ?

4

Re: I ask to prompt how to obtain the data for last period

Vint wrote:

Stax;
Instead of ?

For me is not present
If we take  one previous that it is possible to manage simple exterior
.....
stax