Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.media.kyoto-u.ac.jp!newsfeed.news2me.com!news.glorb.com!postnews.google.com!j33g2000cwa.googlegroups.com!not-for-mail
From: "Stephen.Broberg@gmail.com" <Stephen.Broberg@gmail.com>
Newsgroups: comp.databases.oracle.server
Subject: Re: Any query specialist? you have a challenge
Date: 4 Apr 2006 11:31:47 -0700
Organization: http://groups.google.com
Lines: 11
Message-ID: <1144175507.273836.61400@j33g2000cwa.googlegroups.com>
References: <1144150900.039053.67560@z34g2000cwc.googlegroups.com>
   <1144152371.530641.280980@u72g2000cwu.googlegroups.com>
   <1144154609.076092.192420@e56g2000cwe.googlegroups.com>
   <1144155315.128555.211130@i40g2000cwc.googlegroups.com>
   <1144166139.781382.240730@u72g2000cwu.googlegroups.com>
NNTP-Posting-Host: 129.33.1.37
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1144175512 10746 127.0.0.1 (4 Apr 2006 18:31:52 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Tue, 4 Apr 2006 18:31:52 +0000 (UTC)
User-Agent: G2/0.2
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1,gzip(gfe),gzip(gfe)
Complaints-To: groups-abuse@google.com
Injection-Info: j33g2000cwa.googlegroups.com; posting-host=129.33.1.37;
   posting-account=7iNJ3w0AAACuuyGmYmcx7VVxPAdtWIA6
Xref: dp-news.maxwell.syr.edu comp.databases.oracle.server:264827

You're close, you just have your logic reversed.  Put the sums around
the case statements, instead of inside them, and only group by
customer, like this:

SELECT CustNo
     , sum(case when (...) between 1 and 3 then NoOfOrders else 0 end)
One2Three
     , etc.
  FROM testTable
GROUP BY CustNo;

