dbTalk Databases Forums  

recursive formula help please!

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss recursive formula help please! in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Totti
 
Posts: n/a

Default recursive formula help please! - 01-12-2008 , 05:09 PM






hi all, i have a sales table that i want to get the balance for some
specific condition products,
i am getting the wrong balance since i lack the knowledge of how to do
a recursive formula, you may know that the balance of FEB for instance
depends on JAN so on and so forth so my best attempt to solve the
problem was the following, but it is still wrong, can anybody please
help me correct it?

select TO_CHAR(purinv_1.Inv_Date,'mm') || ' - ' ||
TO_CHAR(purinv_1.Inv_Date,'yy') as "MONTH",
sum(purch_1.qty*purch_1.unit_price) "Total Purchases",
sum(sales_1.qty*prod_1.unit_price) "Total Sales",
(sum(purch_1.qty*purch_1.unit_price))-
(sum(sales_1.qty*prod_1.unit_price))as "Balance"
from purch_1, sales_1, prod_1, salinv_1,purinv_1
where prod_1.code=sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code='Cu-30.1'
group by TO_CHAR(purinv_1.Inv_Date,'mm'),
TO_CHAR(purinv_1.Inv_Date,'yy')
order by TO_CHAR(purinv_1.Inv_Date,'yy')

this makes only a monthly balance but this is not what i want, i want
to tie it to the present balance, or to the sum of previous balances;

Thanks in advance for any help;

Reply With Quote
  #2  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 05:40 PM






Totti schrieb:
Quote:
hi all, i have a sales table that i want to get the balance for some
specific condition products,
i am getting the wrong balance since i lack the knowledge of how to do
a recursive formula, you may know that the balance of FEB for instance
depends on JAN so on and so forth so my best attempt to solve the
problem was the following, but it is still wrong, can anybody please
help me correct it?

select TO_CHAR(purinv_1.Inv_Date,'mm') || ' - ' ||
TO_CHAR(purinv_1.Inv_Date,'yy') as "MONTH",
sum(purch_1.qty*purch_1.unit_price) "Total Purchases",
sum(sales_1.qty*prod_1.unit_price) "Total Sales",
(sum(purch_1.qty*purch_1.unit_price))-
(sum(sales_1.qty*prod_1.unit_price))as "Balance"
from purch_1, sales_1, prod_1, salinv_1,purinv_1
where prod_1.code=sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code='Cu-30.1'
group by TO_CHAR(purinv_1.Inv_Date,'mm'),
TO_CHAR(purinv_1.Inv_Date,'yy')
order by TO_CHAR(purinv_1.Inv_Date,'yy')

this makes only a monthly balance but this is not what i want, i want
to tie it to the present balance, or to the sum of previous balances;

Thanks in advance for any help;
select to_char(trunc(purinv_1.inv_date, 'mm'),'mm"-"yy') as "MONTH",
sum(purch_1.qty * purch_1.unit_price) "Total Purchases",
sum(sales_1.qty * prod_1.unit_price) "Total Sales",
(sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)) as "Balance",
sum((sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)))
over(order by trunc(purinv_1.inv_date, 'mm')) as "Cumulated Balance"
from purch_1, sales_1, prod_1, salinv_1, purinv_1
where prod_1.code = sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code = 'Cu-30.1'
group by trunc(purinv_1.inv_date, 'mm')
order by trunc(purinv_1.inv_date, 'mm')


Best regards

Maxim


Reply With Quote
  #3  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 05:40 PM



Totti schrieb:
Quote:
hi all, i have a sales table that i want to get the balance for some
specific condition products,
i am getting the wrong balance since i lack the knowledge of how to do
a recursive formula, you may know that the balance of FEB for instance
depends on JAN so on and so forth so my best attempt to solve the
problem was the following, but it is still wrong, can anybody please
help me correct it?

select TO_CHAR(purinv_1.Inv_Date,'mm') || ' - ' ||
TO_CHAR(purinv_1.Inv_Date,'yy') as "MONTH",
sum(purch_1.qty*purch_1.unit_price) "Total Purchases",
sum(sales_1.qty*prod_1.unit_price) "Total Sales",
(sum(purch_1.qty*purch_1.unit_price))-
(sum(sales_1.qty*prod_1.unit_price))as "Balance"
from purch_1, sales_1, prod_1, salinv_1,purinv_1
where prod_1.code=sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code='Cu-30.1'
group by TO_CHAR(purinv_1.Inv_Date,'mm'),
TO_CHAR(purinv_1.Inv_Date,'yy')
order by TO_CHAR(purinv_1.Inv_Date,'yy')

this makes only a monthly balance but this is not what i want, i want
to tie it to the present balance, or to the sum of previous balances;

Thanks in advance for any help;
select to_char(trunc(purinv_1.inv_date, 'mm'),'mm"-"yy') as "MONTH",
sum(purch_1.qty * purch_1.unit_price) "Total Purchases",
sum(sales_1.qty * prod_1.unit_price) "Total Sales",
(sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)) as "Balance",
sum((sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)))
over(order by trunc(purinv_1.inv_date, 'mm')) as "Cumulated Balance"
from purch_1, sales_1, prod_1, salinv_1, purinv_1
where prod_1.code = sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code = 'Cu-30.1'
group by trunc(purinv_1.inv_date, 'mm')
order by trunc(purinv_1.inv_date, 'mm')


Best regards

Maxim


Reply With Quote
  #4  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 05:40 PM



Totti schrieb:
Quote:
hi all, i have a sales table that i want to get the balance for some
specific condition products,
i am getting the wrong balance since i lack the knowledge of how to do
a recursive formula, you may know that the balance of FEB for instance
depends on JAN so on and so forth so my best attempt to solve the
problem was the following, but it is still wrong, can anybody please
help me correct it?

select TO_CHAR(purinv_1.Inv_Date,'mm') || ' - ' ||
TO_CHAR(purinv_1.Inv_Date,'yy') as "MONTH",
sum(purch_1.qty*purch_1.unit_price) "Total Purchases",
sum(sales_1.qty*prod_1.unit_price) "Total Sales",
(sum(purch_1.qty*purch_1.unit_price))-
(sum(sales_1.qty*prod_1.unit_price))as "Balance"
from purch_1, sales_1, prod_1, salinv_1,purinv_1
where prod_1.code=sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code='Cu-30.1'
group by TO_CHAR(purinv_1.Inv_Date,'mm'),
TO_CHAR(purinv_1.Inv_Date,'yy')
order by TO_CHAR(purinv_1.Inv_Date,'yy')

this makes only a monthly balance but this is not what i want, i want
to tie it to the present balance, or to the sum of previous balances;

Thanks in advance for any help;
select to_char(trunc(purinv_1.inv_date, 'mm'),'mm"-"yy') as "MONTH",
sum(purch_1.qty * purch_1.unit_price) "Total Purchases",
sum(sales_1.qty * prod_1.unit_price) "Total Sales",
(sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)) as "Balance",
sum((sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)))
over(order by trunc(purinv_1.inv_date, 'mm')) as "Cumulated Balance"
from purch_1, sales_1, prod_1, salinv_1, purinv_1
where prod_1.code = sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code = 'Cu-30.1'
group by trunc(purinv_1.inv_date, 'mm')
order by trunc(purinv_1.inv_date, 'mm')


Best regards

Maxim


Reply With Quote
  #5  
Old   
Maxim Demenko
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 05:40 PM



Totti schrieb:
Quote:
hi all, i have a sales table that i want to get the balance for some
specific condition products,
i am getting the wrong balance since i lack the knowledge of how to do
a recursive formula, you may know that the balance of FEB for instance
depends on JAN so on and so forth so my best attempt to solve the
problem was the following, but it is still wrong, can anybody please
help me correct it?

select TO_CHAR(purinv_1.Inv_Date,'mm') || ' - ' ||
TO_CHAR(purinv_1.Inv_Date,'yy') as "MONTH",
sum(purch_1.qty*purch_1.unit_price) "Total Purchases",
sum(sales_1.qty*prod_1.unit_price) "Total Sales",
(sum(purch_1.qty*purch_1.unit_price))-
(sum(sales_1.qty*prod_1.unit_price))as "Balance"
from purch_1, sales_1, prod_1, salinv_1,purinv_1
where prod_1.code=sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code='Cu-30.1'
group by TO_CHAR(purinv_1.Inv_Date,'mm'),
TO_CHAR(purinv_1.Inv_Date,'yy')
order by TO_CHAR(purinv_1.Inv_Date,'yy')

this makes only a monthly balance but this is not what i want, i want
to tie it to the present balance, or to the sum of previous balances;

Thanks in advance for any help;
select to_char(trunc(purinv_1.inv_date, 'mm'),'mm"-"yy') as "MONTH",
sum(purch_1.qty * purch_1.unit_price) "Total Purchases",
sum(sales_1.qty * prod_1.unit_price) "Total Sales",
(sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)) as "Balance",
sum((sum(purch_1.qty * purch_1.unit_price)) - sum(sales_1.qty *
prod_1.unit_price)))
over(order by trunc(purinv_1.inv_date, 'mm')) as "Cumulated Balance"
from purch_1, sales_1, prod_1, salinv_1, purinv_1
where prod_1.code = sales_1.prod_code
and salinv_1.code = sales_1.inv_code
and salinv_1.cust_code = 'Cu-30.1'
group by trunc(purinv_1.inv_date, 'mm')
order by trunc(purinv_1.inv_date, 'mm')


Best regards

Maxim


Reply With Quote
  #6  
Old   
Totti
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 06:11 PM



Thank you Maxim, this did the job well;

Reply With Quote
  #7  
Old   
Totti
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 06:11 PM



Thank you Maxim, this did the job well;

Reply With Quote
  #8  
Old   
Totti
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 06:11 PM



Thank you Maxim, this did the job well;

Reply With Quote
  #9  
Old   
Totti
 
Posts: n/a

Default Re: recursive formula help please! - 01-12-2008 , 06:11 PM



Thank you Maxim, this did the job well;

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.