![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
hi all i want to generate the total sales of the 3 most sold products of a firm, i ll try to write it here as follows from more than one table but the result i am getting is awful, and has nothing to do with the real thing; take a look please and tell me what and where the problem might be: the result i intend to get is this : Month Year SP-20.1 * * *SP-20.3 * * *SP-20.4 ----- * * * ---- * * * *------------ * *------------ **------------ * *01 2006 * 24,700,000 * * *880,000 * *1,476,000 * *02 2006 * 19,240,000 * * *660,000 * *2,132,000 * *03 2006 * *8,320,000 * * *330,000 * *2,296,000 * *01 2007 * 24,180,000 * * *770,000 * * *902,000 ================================================== i am using the following formula: SELECT TO_CHAR(purinv.Inv_Date,'mm') MONTH ,TO_CHAR(purinv.Inv_Date,'YYYY') YEAR, SUM(DECODE(PURCH.PROD_CODE,'SP-20.2',sales.QTY*prod.unit_price,0)) AS "SP-20.2", SUM(DECODE(PURCH.PROD_CODE,'SP-20.1',sales.QTY*prod.unit_price,0))AS "SP-20.1" , SUM(DECODE(PURCH.PROD_CODE,'SP-20.6',sales.QTY*prod.unit_price,0))AS "SP-20.6" from purinv, purch,prod,sales where purinv.Code = purch.Inv_Code and sales.prod_code = prod.code and purch.Prod_Code in ('SP-20.2', 'SP-20.1', 'SP-20.6') group by TO_CHAR(purinv.Inv_Date,'mm') ,TO_CHAR(purinv.Inv_Date,'YYYY') order by TO_CHAR(purinv.Inv_Date,'YYYY'),TO_CHAR(purinv.Inv _Date,'mm') the result i am getting has 2 wrong things, first of all it is all wrong :-), and second, when a month let us say had not any sales of those 3 product, it omits the whole thing, which something i dont want, for instance since from the 4th of 2006 untill the 12th there has been no sales of this product, but the formula doesnt show 0 as i wanted , instead it throws them out. concerning the result i am getting here it is: MO YEAR * *SP-20.2 * *SP-20.1 * *SP-20.6 -- ---- ---------- ---------- ---------- 01 2006 *497953000 *497953000 *497953000 03 2006 * * * * *0 * * * * *0 * * * * * * *497953000 04 2007 * * * * *0 * * * 497953000 * * * * *0 05 2007 *497953000 * * * * *0 * * * *497953000 07 2007 * * * * *0 * 497953000 * * * *497953000 08 2007 * * * * *0 * 497953000 * * * *497953000 09 2007 *497953000 *497953000 *497953000 11 2007 * * * * *0 * * * * *0 * * * * * * *497953000 *this is crazy i mean , please if you can help me correct the formula! |
#3
| |||
| |||
|
|
hi all i want to generate the total sales of the 3 most sold products of a firm, i ll try to write it here as follows from more than one table but the result i am getting is awful, and has nothing to do with the real thing; take a look please and tell me what and where the problem might be: the result i intend to get is this : Month Year SP-20.1 * * *SP-20.3 * * *SP-20.4 ----- * * * ---- * * * *------------ * *------------ **------------ * *01 2006 * 24,700,000 * * *880,000 * *1,476,000 * *02 2006 * 19,240,000 * * *660,000 * *2,132,000 * *03 2006 * *8,320,000 * * *330,000 * *2,296,000 * *01 2007 * 24,180,000 * * *770,000 * * *902,000 ================================================== i am using the following formula: SELECT TO_CHAR(purinv.Inv_Date,'mm') MONTH ,TO_CHAR(purinv.Inv_Date,'YYYY') YEAR, SUM(DECODE(PURCH.PROD_CODE,'SP-20.2',sales.QTY*prod.unit_price,0)) AS "SP-20.2", SUM(DECODE(PURCH.PROD_CODE,'SP-20.1',sales.QTY*prod.unit_price,0))AS "SP-20.1" , SUM(DECODE(PURCH.PROD_CODE,'SP-20.6',sales.QTY*prod.unit_price,0))AS "SP-20.6" from purinv, purch,prod,sales where purinv.Code = purch.Inv_Code and sales.prod_code = prod.code and purch.Prod_Code in ('SP-20.2', 'SP-20.1', 'SP-20.6') group by TO_CHAR(purinv.Inv_Date,'mm') ,TO_CHAR(purinv.Inv_Date,'YYYY') order by TO_CHAR(purinv.Inv_Date,'YYYY'),TO_CHAR(purinv.Inv _Date,'mm') the result i am getting has 2 wrong things, first of all it is all wrong :-), and second, when a month let us say had not any sales of those 3 product, it omits the whole thing, which something i dont want, for instance since from the 4th of 2006 untill the 12th there has been no sales of this product, but the formula doesnt show 0 as i wanted , instead it throws them out. concerning the result i am getting here it is: MO YEAR * *SP-20.2 * *SP-20.1 * *SP-20.6 -- ---- ---------- ---------- ---------- 01 2006 *497953000 *497953000 *497953000 03 2006 * * * * *0 * * * * *0 * * * * * * *497953000 04 2007 * * * * *0 * * * 497953000 * * * * *0 05 2007 *497953000 * * * * *0 * * * *497953000 07 2007 * * * * *0 * 497953000 * * * *497953000 08 2007 * * * * *0 * 497953000 * * * *497953000 09 2007 *497953000 *497953000 *497953000 11 2007 * * * * *0 * * * * *0 * * * * * * *497953000 *this is crazy i mean , please if you can help me correct the formula! |
#4
| |||
| |||
|
|
hi all i want to generate the total sales of the 3 most sold products of a firm, i ll try to write it here as follows from more than one table but the result i am getting is awful, and has nothing to do with the real thing; take a look please and tell me what and where the problem might be: the result i intend to get is this : Month Year SP-20.1 * * *SP-20.3 * * *SP-20.4 ----- * * * ---- * * * *------------ * *------------ **------------ * *01 2006 * 24,700,000 * * *880,000 * *1,476,000 * *02 2006 * 19,240,000 * * *660,000 * *2,132,000 * *03 2006 * *8,320,000 * * *330,000 * *2,296,000 * *01 2007 * 24,180,000 * * *770,000 * * *902,000 ================================================== i am using the following formula: SELECT TO_CHAR(purinv.Inv_Date,'mm') MONTH ,TO_CHAR(purinv.Inv_Date,'YYYY') YEAR, SUM(DECODE(PURCH.PROD_CODE,'SP-20.2',sales.QTY*prod.unit_price,0)) AS "SP-20.2", SUM(DECODE(PURCH.PROD_CODE,'SP-20.1',sales.QTY*prod.unit_price,0))AS "SP-20.1" , SUM(DECODE(PURCH.PROD_CODE,'SP-20.6',sales.QTY*prod.unit_price,0))AS "SP-20.6" from purinv, purch,prod,sales where purinv.Code = purch.Inv_Code and sales.prod_code = prod.code and purch.Prod_Code in ('SP-20.2', 'SP-20.1', 'SP-20.6') group by TO_CHAR(purinv.Inv_Date,'mm') ,TO_CHAR(purinv.Inv_Date,'YYYY') order by TO_CHAR(purinv.Inv_Date,'YYYY'),TO_CHAR(purinv.Inv _Date,'mm') the result i am getting has 2 wrong things, first of all it is all wrong :-), and second, when a month let us say had not any sales of those 3 product, it omits the whole thing, which something i dont want, for instance since from the 4th of 2006 untill the 12th there has been no sales of this product, but the formula doesnt show 0 as i wanted , instead it throws them out. concerning the result i am getting here it is: MO YEAR * *SP-20.2 * *SP-20.1 * *SP-20.6 -- ---- ---------- ---------- ---------- 01 2006 *497953000 *497953000 *497953000 03 2006 * * * * *0 * * * * *0 * * * * * * *497953000 04 2007 * * * * *0 * * * 497953000 * * * * *0 05 2007 *497953000 * * * * *0 * * * *497953000 07 2007 * * * * *0 * 497953000 * * * *497953000 08 2007 * * * * *0 * 497953000 * * * *497953000 09 2007 *497953000 *497953000 *497953000 11 2007 * * * * *0 * * * * *0 * * * * * * *497953000 *this is crazy i mean , please if you can help me correct the formula! |
#5
| |||
| |||
|
|
hi all i want to generate the total sales of the 3 most sold products of a firm, i ll try to write it here as follows from more than one table but the result i am getting is awful, and has nothing to do with the real thing; take a look please and tell me what and where the problem might be: the result i intend to get is this : Month Year SP-20.1 * * *SP-20.3 * * *SP-20.4 ----- * * * ---- * * * *------------ * *------------ **------------ * *01 2006 * 24,700,000 * * *880,000 * *1,476,000 * *02 2006 * 19,240,000 * * *660,000 * *2,132,000 * *03 2006 * *8,320,000 * * *330,000 * *2,296,000 * *01 2007 * 24,180,000 * * *770,000 * * *902,000 ================================================== i am using the following formula: SELECT TO_CHAR(purinv.Inv_Date,'mm') MONTH ,TO_CHAR(purinv.Inv_Date,'YYYY') YEAR, SUM(DECODE(PURCH.PROD_CODE,'SP-20.2',sales.QTY*prod.unit_price,0)) AS "SP-20.2", SUM(DECODE(PURCH.PROD_CODE,'SP-20.1',sales.QTY*prod.unit_price,0))AS "SP-20.1" , SUM(DECODE(PURCH.PROD_CODE,'SP-20.6',sales.QTY*prod.unit_price,0))AS "SP-20.6" from purinv, purch,prod,sales where purinv.Code = purch.Inv_Code and sales.prod_code = prod.code and purch.Prod_Code in ('SP-20.2', 'SP-20.1', 'SP-20.6') group by TO_CHAR(purinv.Inv_Date,'mm') ,TO_CHAR(purinv.Inv_Date,'YYYY') order by TO_CHAR(purinv.Inv_Date,'YYYY'),TO_CHAR(purinv.Inv _Date,'mm') the result i am getting has 2 wrong things, first of all it is all wrong :-), and second, when a month let us say had not any sales of those 3 product, it omits the whole thing, which something i dont want, for instance since from the 4th of 2006 untill the 12th there has been no sales of this product, but the formula doesnt show 0 as i wanted , instead it throws them out. concerning the result i am getting here it is: MO YEAR * *SP-20.2 * *SP-20.1 * *SP-20.6 -- ---- ---------- ---------- ---------- 01 2006 *497953000 *497953000 *497953000 03 2006 * * * * *0 * * * * *0 * * * * * * *497953000 04 2007 * * * * *0 * * * 497953000 * * * * *0 05 2007 *497953000 * * * * *0 * * * *497953000 07 2007 * * * * *0 * 497953000 * * * *497953000 08 2007 * * * * *0 * 497953000 * * * *497953000 09 2007 *497953000 *497953000 *497953000 11 2007 * * * * *0 * * * * *0 * * * * * * *497953000 *this is crazy i mean , please if you can help me correct the formula! |
#6
| |||
| |||
|
#7
| |||
| |||
|
#8
| |||
| |||
|
#9
| |||
| |||
|
#10
| |||
| |||
|
|
David, that was not the same problem this is another one, that is not working with the (+) David told me about;even though for the first one it worked; these data are real, and the way i want them to be is as the first table, i gave in the former message, while when using the formula i put, i am getting resultsas the second table where all the numbers are 497953000 or 0, and this is surely wrong. **it is not that i dont take advice well, it is only that i am in the very first steps of learning SQL, and there may be things that you here give but i dont even understand how they work, i need more work with SQL, i am not a kind of dumb that doesnt take advices, i m just without experience yet. and there are many things i dont know. Thanks again for your understanding and for your help! |
![]() |
| Thread Tools | |
| Display Modes | |
| |