How to sum these output values
Posted on
16th Feb 2014 07:03 pm by
admin
Hi
I need sum the month totals
SELECT region_name, area_name
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '07' THEN sales_target END) AS jul
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '08' THEN sales_target END) AS aug
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '09' THEN sales_target END) AS sep
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '10' THEN sales_target END) AS oct
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '11' THEN sales_target END) AS nov
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '12' THEN sales_target END) AS dec
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '01' THEN sales_target END) AS jan
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '02' THEN sales_target END) AS feb
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '03' THEN sales_target END) AS mar
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '04' THEN sales_target END) AS apr
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '05' THEN sales_target END) AS may
,SUM (CASE WHEN SUBSTR(yr_mth,5,2) = '06' THEN sales_target END) AS jun
FROM sales_forecast WHERE REGION_NAME like nvl('®IONNAME','%') AND
AREA_NAME like nvl('&AREANAME','%') AND
yr_mth=nvl('&Year',substr(yr_mth,1,4))||NVL(DECODE('&Month','JAN','01','FEB','02','MAR','03','APR','04','MAY','05',
'JUN','06','JUL','07','AUG','08','SEP','09','NOV','11','DEC','12'),substr(yr_mth,5,6))
GROUP BY region_name, area_name
ORDER BY region_name, area_name
Requirment
region_name, area_name, jul, aug ................ jun
abc xyz 10, 20.....................30
ccc ggg 20, 30.....................40
total 30, 50 ...................70
thanks
No comments posted yet
Your Answer:
Login to answer
245
23
Other forums
socket communication between c++/java and sending image
hi,
i have a class in c++ called win32_sockserver which creates socket to java. i am trying
question about stripslashes and real_escape_string
im cleaning up an old app that I wrote fixing some of the vulernabilities from attacks.
I hav
why this query can delete duplicates ?
why this query can delete duplicates ? Anybody can give me the detailed explanation ?
Tha
how do i display data on a page from mysql
1 - do i use this code at the top of each of my page i wish to only alow access if there as been a s
Simple Question
I know this is a simple question, that if I knew what it was technically called i could probably loo
PHP Blog help
Need help with posting comments in a word press blog? I have a comments page where the comments are
Keep newlines from textarea?..
I'm creating a simple encoding program, and what I want it to do is retain the newlines, as echoing
Random date selection
i want to select random date with time(hour+minutes+sec) where date is specified(10/22/2009) and tim
WM transfer order: confirm different batch than proposed by system
Hi folks,
following scenario: we have a full WM with mixed batch numbers allowed in stora
natcasesort works on one server but not on another
Hi
I have a problem that I was hoping that someone can help me with.
I'm trying to use