Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
A high performance database engine using optimized data access for all development environments including Delphi, Visual Studio .NET, Visual Basic, Visual FoxPro. and more. Learn More
  #1  
Old September 12th, 2003, 03:29 AM
katyal_rinku katyal_rinku is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 1 katyal_rinku User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
decode - designing query - please help

I am not able to write one query.....actually the problem is quite big..but for the sake of clarity i will putting the same in parts.

consider the following table with below mentioned colums.

MSSA_SALES
--------------------
salesman
product
quantity
sal_month
--------------------

The table contains rows of sales figures for different salesman/product/month.

Like

salesman product quantity sal_month
----------------------------------------------------------
john Butter 10 01-apr-02
Smith Cheese 20 01-apr-02
John Cheese 1 01-apr-02

john Butter 10 01-dec-02
Smith Cheese 20 01-dec-02
John Cheese 1 01-dec-02

john Butter 10 01-apr-03
Smith Cheese 20 01-apr-03
John Cheese 1 01-apr-03
paul powder 53 01-aug-03
adams chocolate 43 01-aug-03

now i want the output in following format.

Butter Cheese Powder chocolate
John
aug_03 20 34 56 0
Cum_02 100 20 23 24
Cum_03 5 4 5 0

Smith
aug_03 23 44 0 34
Cum_02 11 11 11 11
Cum_03 1 2 3 4


---------------Now the requirement is-----------------

In first row it should show the value of sales for one month say 01-aug-03.
In second row it should show the value of sales cumulative i.e from 01-apr-02 to 01-mar-03.(cum_02)
In second row it should show the value of sales cumulative i.e from 01-apr-03 to 01-aug-03.(cum_03)
I am able to produce , what is required in first row and third row the problem is coming for 2nd row i.e cum_02 only.

I have written following query

select salesman,
product,sum(decode(to_char(sal_month),'01-AUG-03',wss_qty,0))
aug_03,
sum(wss_qty) cum_03
from mssav_wd_sales_summary
where sal_month between '01-apr-03' and '01-sep-03'
group by salesman,product
/

it will give me aug_03 and cum_03 figures but not cum_02.If i change the where condition as "where sal_month between '01-apr-02' and '01-aug-03'"then the whole outut will be wrong because cum_03 will start including the figures from 01-apr-02 , but i want it to include period from 01-apr-03 onwards only.

So please help me in designing the query.
Then i will reuqest for the second part of my problem.


Regards,
Rajeev Katyal

Reply With Quote
  #2  
Old September 18th, 2003, 11:42 AM
shafique shafique is offline
Senior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 305 shafique User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 45 m 20 sec
Reputation Power: 5
decode - designing query

Your WHERE clause requires to meet two (2) condition
(1) for cum_02 date range is 01-apr-02 to 01-mar-03
(2) for cum_03 date range is 01-apr-03 to 01-aug-03

because of this reason, you should use SET OPERATORS like UNION, or UNION ALL. query would be as follow:

select salesman,
product,sum(decode(to_char(sal_month),'01-AUG-03',wss_qty,0))
aug_03, 0 cum_2,
sum(wss_qty) cum_03,
0 cum_02
from mssav_wd_sales_summary
where sal_month between '01-apr-03' and '01-sep-03'
group by salesman,product
UNION -- set operator
/* add new query for cum_02 */
select salesman,
product, 0 aug_03, sum(decode(to_char(sal_month),'01-APR-03',wss_qty,0))
apr_02,
0 cum_03,
sum(wss_qty) cum_02
from mssav_wd_sales_summary
where sal_month between '01-apr-03' and '01-sep-03'
group by salesman,product
/
that you mean?

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > decode - designing query - please help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway