Help with Sql for the annual report by month

Hi, I got the task of creating an annual report each month that shows the benefits of the enterprise by month and total in the last column to show what branch was the hightest income.
Branch | January | February | March | April | Can | June... | Total |
ABC | $0.00 | $0.00 | $0.00 | $0.00 | $0.00 | $0.00 | Total of the Amt |
DEF | $18.01. $3.88. $18.01. $4.12 | $18.01. $3.97 | Total of the Amt |

Can someone please help me give an idea of how to write sql for this report... ? I build subqueries for everymonth giving dates for Jan/Feb/March... but I think that this is not the right way to do it...
-----------------------------------------------------------------------------------------------------------------------
SELECT
Sum (a.Commission) December,
Sum (b.Commission) November
Of
(
Select
c.account_ID,
c.Officer,
c.account_product_class_id,
Sum (c.dp_monthly_premium) Commission
Of
c contract
Where
c.account_ID = 109 and
c.Status = 'APPROVED' and
c.protection_effective between December 1, 2009 "and on December 31, 2009"
Group by
c.account_ID,
c.Officer,
c.account_product_class_id
),
(
Select
c.account_ID,
c.Officer,
c.account_product_class_id,
Sum (c.dp_monthly_premium) Commission
Of
c contract
Where
c.account_ID = 109 and
c.Status = 'APPROVED' and
c.protection_effective between November 1, 2009 "-November 30, 2009"
Group by
c.account_ID,
c.Officer,
c.account_product_class_id
) b
-----------------------------------------------------------------------------------------------------------
I always hight hope this forum. So please help. Thanks in advance.

Published by: Aditi_Seth on January 26, 2010 14:29

You may reach the columns using decode:

Select sum (decode (to_char (c.protection_effective, 'MM'), 1, c.dp_monthly_premium, 0)) January
, sum (decode (to_char (c.protection_effective, 'MM'), 2, c.dp_monthly_premium, 0)) February

etc.

At least, this will improve efficiency, because you need only make one pass.

no guarantee that the media are quite right - I did not execute the query, but I think that you should get the idea!

Tags: Oracle Development

Similar Questions

  • Need help with SQL for the following logic.

    I have a table with 3 columns and the following data:
    DATE NAME S_NO
    1 ABC1 JANUARY 1, 2001
    1 ABC2 JANUARY 10, 2001
    1 ABC3
    1 ABC4
    ABC1 2 1 DECEMBER 2010
    ABC2 2
    2 ABC3 DECEMBER 10, 2010
    2 ABC4 DECEMBER 5, 2010
    3 XYZ1 FEBRUARY 1, 2001
    3 XYZ2 FEBRUARY 2, 2001

    I need to retrieve the value of NAME for each S_NO corresponding to the maximum DATE. In the above example, it will be:
    1 ABC2
    2 ABC3
    3 XYZ2
    /* Formatted on 9/10/2012 2:50:13 PM (QP5 v5.139.911.3011) */
    WITH t AS (SELECT 1 S_NO, 'ABC1' NAME, '1-JAN-2001' dt FROM DUAL
               UNION ALL
               SELECT 1, 'ABC2', ' 10-JAN-2001' FROM DUAL
               UNION ALL
               SELECT 1, 'ABC3', NULL FROM DUAL
               UNION ALL
               SELECT 1, 'ABC4', NULL FROM DUAL
               UNION ALL
               SELECT 2, 'ABC1', '1-DEC-2010' FROM DUAL
               UNION ALL
               SELECT 2, 'ABC2', NULL FROM DUAL
               UNION ALL
               SELECT 2, 'ABC3', '10-DEC-2010' FROM DUAL
               UNION ALL
               SELECT 2, 'ABC4', '5-DEC-2010' FROM DUAL
               UNION ALL
               SELECT 3, 'XYZ1', '1-FEB-2001' FROM DUAL
               UNION ALL
               SELECT 3, 'XYZ2', '2-FEB-2001' FROM DUAL)
    SELECT *
      FROM (SELECT S_NO,
                   name,
                   RANK ()
                   OVER (PARTITION BY s_no
                         ORDER BY TO_DATE (dt, 'dd-mon-yyyy') DESC)
                      rk
              FROM t
             WHERE dt IS NOT NULL)
     WHERE 1 = RK
    
  • IM ' all the app "creative cloud 'all-inclusive' adobe, the price says $ 49 99 / mo for the annual plan, paid monthly. What means the small 99 means beside the number 49. This means that the price is 49.99 USD for annual paid monthly plan?

    IM ' all the app "creative cloud 'all-inclusive' adobe, the price says $ 49 99 / mo for the annual plan, paid monthly. What means the small 99 means beside the number 49. This means that the price is 49.99 USD for annual paid monthly plan?

    Yes. USD 49. 99

    Fenja

  • Help with buttons for the slideshow

    I'm working on my first flash project.  I created a simple slideshow image 4.  I have created 4 buttons that when clicked, jump to this image in the panel mounting.  I added rollover States for the button. Everything works as I want it.

    My question is how can I get the buttons to have a different look when this particular image is active?

    For example.  When the slideshow is on the 2nd picture, I want 2 button to have an active state (different look as the other three buttons).

    Here's my project file.

    Thank you

    You must use the movieclip buttons.

  • Can anyone help with SQL for update?

    Hello

    can someone help me with this code


    2 tables.
    Table 1 = User_master
    Table 2 = update_users

    I need to update user_master as follows...
    Update user_master
    set status = 'I '.
    When user_id IN)


    problem is that I have over 10 k user_id to update.
    So created a new table called update_users and imported from all user_id in this table.
    How can I read all user_id table, then update the status for all user_master column
    ID of users found in update_users?


    I already tried this...
    Update user_master p.user_id p
    set status = 'I '.
    When user_id = (select user_id from update_users where p.user_id = user_id)

    It did not work-
    ERROR on line 2:
    ORA-01427: einreihig subquery returns multiple rows


    Thank you

    have you tried

     update user_master
     set status = 'I'
     where user_id IN (select user_id from update_users);
    

    Published by: release 6' - 8 "June 1, 2010 16:23

  • Help with Javascript for the button Delete

    Hi, Im new JavaScript and have my code works partially, but the trouble with a nested if-then-else statement.

    I have a page element, P4_COUNT, and if its value is 0, the button Delete will allow the user to delete the record. If the number is > 0, a message should appear stating that the record cannot be deleted. That's what I have so far and it works, but the first ELSE is misplaced. This code is the URL target for my button remove.

    JavaScript:var response; response = confirm ("are you sure you want to delete this POC?'");
    If {(response)
    If (document.getElementById('P4_COUNT').value == 0) {}
    doSubmit ('DELETE');
    }
    }
    else {-this other fires when the user hits cancel on the first question above not what I want, I want another one here who said only: "removal cancelled '"}
    -This one should only be fired if p4_count is not equal to 0
    var answer2;
    answer2 = confirm ('you cannot remove this POC, that this POC is associated with a RIF.');
    If {(answer2)
    Alert ('cancelled deletion');
    }
    else {}
    Alert ('cancelled deletion');
    }
    }


    The above should follow this logic:

    Are you sure you want to delete this POC?
    Yes - if p4_count = 0 then
    delete the record
    on the other
    second line: cannot delete this record
    OK - prompt removal cancelled
    Cancel - prompt removal cancelled
    end if;
    Cancel - prompt removal cancelled


    Help, please. Thank you, Laura

    Published by: user8936524 on May 10, 2010 14:14

    Hello

    Try if it works. I didn't test it

    javascript:if($v('P4_COUNT')*1==0){
    var answer=confirm('Are you certain you want to delete this POC?');
    if(answer){doSubmit('DELETE');}
    else{alert('Deletion Cancelled');}
    }else{alert('You may not delete this POC, as this POC is associated to an FRR.');}
    

    BR, Jari

  • HELP with animation for the buttons (I tried to search for days for solution)

    Hellooo

    I tried to watch the discussions here for a solution, but I can not find... can someone help me please?

    I design a website in flash8... now, I created a few buttons and I want that when I click the button stars will fly on their part and there will be a sound... I have already created the animation of the separately-star and it's in the library, I also sound file... I just don't remember how put everything together... can someone please remind me what to do step by step so When I press the button that the stars will fly directly from the button and the sound will play? pleaseeeeeeeee, it's very very important to me... I'd be grateful < 3

    in your library, double-click your button.  Select the image down, and in the properties panel, select your sound and assign its sync to the event.  then drag your animation to your library on the stage.

  • Need help with italics for the ePub and InDesign CS5

    Can anyone one help out me. I can't find the answer to this and I know it must be simple, I just lack.

    I create an ePub from InDesign CS5. All I want to do is have the italics that are displayed in the text box in InDesign, see the in the epub file.

    I prefer not to say what I did (I think I've tried everything, but obviously I got them all wrong, so no point listing them) and I hope that someone can make a simple guide, step by step how to make italics appear in the ePub file.

    Sorry if this question is under everyone, it's really annoying that I can't figure this on my own.

    Yes unfortunately sometimes does. ID is really a ship in order to get the content in epub format.

    You must go through your CSS for every job.

    Addition of

    serif; or without serifs; After each occorence a police.

    also, most in CS5 importanley make sure you have font name in the top of the CSS file "" round then, otherwise it appears correctly in the Adobe Digital Editions software, actually to check the rest of the code in this a well for example:

    {@font-face}
    Police-family: Minion Pro;
    make-style: normal;
    make-weight: normal;
    SRC:URL("fonts/MinionPro-regular.OTF");
    }

    I really only the minimum required in ID and do the rest in dreamweaver

  • can anyone help with drivers for Minolta Scan3 double for the Vista operating system

    If anyone can help with drivers for Minolta Dualscan 3 working with Vista?  3 Dualscan will work with Windows 7 or Linux?

    Hi Mike,.

    You can download and install the drivers for Minolta Dualscan 3 from this link.

    http://onyxftp.mykonicaminolta.com/download/Search.aspx?HT=

    Hope the helps of information.

    Please post back and we do know.

  • Help with SQL Query (Subselects)

    Hello community,

    IAM a new Member in this forum. The first excuse my English, my native language is German.
    In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
    I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.

    In this case, I have 2 tables:
    Table 1:
    ID; ORDER_NR; DESCRIPTION; CREATE_DATE
    1; A500236; CLEAN HOUSE; 20/02/2012
    2; A623555; REPAIR CAR; 10/01/2012
    3; A866944; MAINTAIN EQUIPMENT; 11/02/2012

    Table 2:
    ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
    1; A500236; A; 21/02/2012; W0010
    2; A500239; F; 21/02/2012; W0010
    3; A500239; S; 22/02/2012; W0027
    4; A500239; R; 23/02/2012; H0034
    5; A500239; U; 25/02/2012; L0099
    6; A263555; A; 15/01/2012; G0009
    7; A263555; C; 17/01/2012; S0039
    5 V A263555; R; 18/01/2012; K0059
    9; A263555; U; 19/01/2012; A0048
    10; A866944; A; 13/02/2012; H0034
    11; A866944; B; 13/02/2012; L0035
    12; A866944; G; 17/02/2012; D0084
    13; A866944; U; 23/02/2012; S0039

    And the result of my query should look like this:
    ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
    A500236; OWN HOME; 20/02/2012; 5; 3; 1
    A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
    A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3

    The age of my query result should be calculated from the date of the creation of the order.
    I would like to know 2 things, one is how old was the order when they reached this status, R and U.
    The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
    It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column

    I hope you all know what I mean and what result to expect.

    Thanks for your help.

    Reinhard W.

    Hi, Reinhard,

    990524 wrote:
    Hi Frank,.

    I thank you for your professional response and excuse my non-professional way to clarify my question.
    I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?

    You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
    All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.

    I have already noticed that the syntax SQL for Oracle differ from other DBMSS.

    Yes and some features are different in different products.

    Your query works perfectly, thank you.

    Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.

    Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.

    My table contains the Date and time in a row, I forgot to mention that.

    After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.

    I tried something like this:

    SYSDATE - MIN ( CASE
                        WHEN  t2.wo_step = 'A'
                  THEN  t2.step_date
              END
               ) AS Age_A
    

    But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.

    There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.

  • Need help with Sql Tunning

    Under Update taking 2 h complete 3000 sets.

    UPDATE ARR_TRANSACTIONS ARR

    SET = NUMBER99

    (SELECT ARR_1.NUMBER99

    OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH

    WHERE ARR_1.ARR_ID = BH. ARR_ID

    AND BH. FLAG = "Y".

    AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID

    AND ARR_1.NUMBER9 IS NOT NULL

    AND ROWNUM = 1)

    WHERE ARR BATCH_ID = 26219

    AND ARR. NUMBER99 IS NULL

    I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.

    Please help with SQL.

    I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.

    In the given situation, I would check:

    • is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
    • Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.

    To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.

    If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.

  • I ask for the annual subscription, cancellation of a monthly payment of creative photography cloud adobe.

    I ask for the annual subscription, cancellation of a monthly payment of creative photography cloud adobe.

    Cancel your membership Adobe Creative Cloud

    To the link below, click on the still need help? option in the blue box below and choose the option to chat or by phone...

    Make sure that you are logged on the Adobe site, having cookies enabled, clearing your cookie cache.  If he continues to not try to use a different browser.

    https://helpx.Adobe.com/contact.html?step=CCSN_membership-account-payment_cancel-your-memb ership_stillNeedHelp

  • I made the payment for the annual program on October 14 and be required ro balance once again, why?

    I made the payment for the annual program on October 14 and be required ro balance once again, why?

    Hello

    You can refer to the instructions in the links below:

    Connect and disconnect activate Cloud Creative applications

    Applications creative Cloud back in test mode after an update until 2015 for CC

    Activation and deactivation of troubleshooting

    Creating cloud connection errors

    Evaluation mode showing creative cloud

    Let us know if that helps.

    Kind regards

    Bani

  • I have a CC to individuals on the annual plan paid monthly membership. How to pass it to the CC for the teams plan so that I can add my first certificate of employee?

    I have a CC to individuals on the annual plan paid monthly membership. How to pass it to the CC for the teams plan so that I can add my first certificate of employee?

    Hi Alexalloy,

    This should help. Cancel your subscription or membership. Cloud Creative

    See you soon!

    ~ David

  • Just upgraded to Vista Home Premium to XP. Got a Packard Bell with RF for the Media Center remote control, worked fine with XP, but is no longer compatible with Vista.

    after update to XP media center units Vista remote control

    Just upgraded to Vista Home Premium to XP.  Got a Packard Bell with RF for the Media Center remote control, worked fine with XP, but is no longer compatible with Vista.  I checked the usb driver for the usb XF-10 rf remote receiver and it is fine, uninstalled and reinstalled it.  Handset was working fine a few days ago.  I also went in 'Administrator', 'services' and then active HID, but it still does not work.  Media works well, but it would be nice to have the operation of the remote control!  Not particularly computer, simply suggestions please!  Thank you, Nick.

    Hi Nicolas,

    I suggest you to check the battery. Additionally, make sure that you have installed the right drivers for you Consumer IR Port.

    For more information, you can check the link below,

    http://www.PackardBell.com/index.html

Maybe you are looking for

  • IMessage IOS 10 Force to send SMS

    The IOS 10, you can is more keep your iMessage on hold and get a screen that appears and says "Send as a text Message" now a bubble appears with an exclamation mark, thumbs up/down, etc. When I'm in and out of service that may take several minutes fo

  • Yoga 900 - Auto Rotation not working / present

    Hello Well, after my new 900 Yoga for a few days, I turned it off for the first time tonight. Subsequently the auto rotation function had disappeared. No more option in the display settings and registry keys for automatic rotation have been set to 0.

  • T410 - devices without drivers

    Hi guys, I just did a clean install on my T410 (Type: 2537 RY9) and I have 2 unmanned devices which are: Base system deviceNetwork controller Im working on Win 7 x 64. I think that the absence of these factors is causing my LAN to do not be able to c

  • How to do the sync with notifier

    Hi all! Now what I'm trying to do is to do a sync. A series of signal keeps coming back, and a counter records the number. And I also have a data acquisition to output voltages. Now I want that whenever the meter changes, a change in the production o

  • How can I get the software on the WM market with debit card... I also note that my home country Zambia is not even on the country or State drop-down list.

    Remember - this is a public forum so never post private information such as numbers of mail or telephone! Ideas: You have problems with programs Error messages Recent changes to your computer What you have already tried to solve the problem