Help with Sql for Annual Report per month

Hi, I have been given the task to create an annual report by month that would show company's profits per month and totals in the last column to show which branch had the hightest income.
Branch||January||February||March||April||May||June....||Total||     
ABC ||$0.00 ||$0.00 ||$0.00||$0.00||$0.00||$0.00||Total Amt||
DEF ||$18.01 ||$3.88 ||$18.01||$4.12||$18.01||$3.97||Total Amt||
Can anyone please help me in giving an idea of how to write sql for this report..? I am building sub-queries for everymonth by giving the dates for Jan/Feb/March..but I think this is not the right way to do this....
SELECT
sum(a.commission) December,
sum(b.commission) November
FROM
Select
c.account_id,
c.officer,
c.account_product_class_id,
sum(c.dp_monthly_premium) Commission
From
contract c
Where
c.account_id=109 and
c.status='APPROVED' and
c.protection_effective between '01-DEC-2009' and '31-DEC-2009'
Group by
c.account_id,
c.officer,
c.account_product_class_id
) a,
Select
c.account_id,
c.officer,
c.account_product_class_id,
sum(c.dp_monthly_premium) Commission
From
contract c
Where
c.account_id=109 and
c.status='APPROVED' and
c.protection_effective between '01-NOV-2009' and '30-NOV-2009'
Group by
c.account_id,
c.officer,
c.account_product_class_id
) b
I always have hight hope from this forum. So please help. Thanks in advance.
Edited by: Aditi_Seth on Jan 26, 2010 2:29 PM

You may try a group report on one simple query like:
Select
c.account_id, c.officer, to_char(c.protection_effective, 'MM') month
sum(c.dp_monthly_premium) Commission
From
contract c
Where
c.status='APPROVED' and .....
Group by
c.account_id
c.officer,
to_char(c.protection_effective, 'MM')
break/gropu on account_id, c.officer, to_char(c.protection_effective, 'MM') and total will be automatically calculated by Reports.

Similar Messages

  • Need help with SQL for Pie Chart

    I am trying to create a pie charge which would have 3 slices.
    Following sql gives me the expected values when I run the sql command:
    select
    round(avg(CATEGORY_1 + CATEGORY_2 + CATEGORY_3 + CATEGORY_4 + CATEGORY_5),0) "OD Engagements",
    round(avg(CATEGORY_6 + CATEGORY_7 + CATEGORY_13),0) "Talent Engagements",
    round(avg(CATEGORY_8 + CATEGORY_9 + CATEGORY_10 + CATEGORY_11 + CATEGORY_12),0) "Other Engagements"
    from OTD_PROJECT
    where STATUS in ('Open','Hold')
    I get 3 columns labeled: OD Engagements, Talent Engagements and Other Engagements with the correct averages based on the the data.
    I have tried several ways to try to get this to work in the SQL for a pie chart, but keep getting the invalid sql message and it won't save. I also tried saving without validation, but no data is shown on the chart at all.
    I want to have a pie, with 3 slices, one labeled OD Engagements with a value of 27, one labeled Talent Engagements with a value of 43 and one labeled Other Engagements with a value of 30. Then I want to be able to click on each pie slice to drill down to a secondary pie chart that shows the breakdown based on the categories included in that type.
    Since I am not grouping based on an existing field I an unsure what the link and label values should be in the chart sql.

    You'll need something like the below. I have no idea what the URL for the drilldown needs to be. It should create an appropriate link in your app for the particular slice. Mainly the code below breaks the SQL results into three rows rather than three columns. It may well have a syntax error since I can't test.
    select linkval  AS LINK,
           title    AS LABEL,
           calc_val AS VALUE
    FROM   (SELECT 'OD Engagements' AS title,
                   round(avg(CATEGORY_1 + CATEGORY_2 + CATEGORY_3 + CATEGORY_4 + CATEGORY_5),0) AS calc_val,
                   'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
            from   OTD_PROJECT
            where  STATUS in ('Open','Hold')
            UNION ALL
            SELECT 'Talent Engagements' AS title,
                   round(avg(CATEGORY_6 + CATEGORY_7 + CATEGORY_13),0) AS calc_val,
                   'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
            from   OTD_PROJECT
            where  STATUS in ('Open','Hold')
            UNION ALL
            SELECT 'Other Engagements' AS title,
                   round(avg(CATEGORY_8 + CATEGORY_9 + CATEGORY_10 + CATEGORY_11 + CATEGORY_12),0) AS calc_val,
                   'f?p=???:???:' || v('APP_SESSION') || '::NO:?' AS LINKVAL
            from   OTD_PROJECT
            where  STATUS in ('Open','Hold')
           );

  • Help with sql for dial graph

    Hi
    I have the following SQL query
    select (count(select status from tbl_issues where status = 'Open' or status ='On-Hold') - count(select status from tbl_issues where status = 'Closed')) value , 100 max_value
    from tbl_issues
    when I save changes it comes up with the following errors
    1 error has occurred
    Failed to parse SQL query:
    select (count(select status from tbl_helpdesk_calls where status = 'Open' or status ='On-Hold') - count(select status from tbl_helpdesk_calls where status = 'Closed')) value , 100 max_value from TBL_HELPDESK_CALLS
    ORA-00936: missing expression
    Certain queries can only be executed when running your application, if your query appears syntactically correct, you can save your query without validation (see options below query source).
    what I want to do is display on the dial chart whether the performance of a helpdesk is poor or bad using the dials.
    thanks for your help

    Hi,
    I did wonder about the "100 MAX_VALUE" setting!
    For our help desk system (not in ApEx), they have statistics by month. There is also a graph showing how long it took them to resolve calls. You might consider something like that instead?
    Regards
    Andy

  • Can Someone help with SQL for update ?

    Hi,
    can someone help me with this code
    2 tables.
    table 1 = User_master
    table 2 = update_users
    I need to update user_master like so...
    update user_master
    set status = 'I'
    where user_id IN ()
    problem is I have to over 10k user_id to update.
    So created new table called update_users and imported all user_id's into that table.
    How can I read all user_id's from that table, then update user_master status column for all
    users id's found in update_users ?
    I already tried this...
    update p.user_id from user_master p
    set status = 'I'
    where user_id = (select user_id from update_users where p.user_id=user_id)
    It did not work -
    ERROR at line 2:
    ORA-01427: single-row subquery returns more than one row
    Thanks,

    There are no duplicates. Each user_id is unique.Are you sure? the error message indicates otherwise. You might see if the following query returns any rows;
    select user_id, count(*)
    from update_users
    group by user_id
    having count(*) > 1;Also, you might want to post the exact statement that you used to generate the error. The statement that you posted raises an error de to the syntax;
    update p.user_id from user_master p
    set status = 'I'
    where user_id = (select user_id
                     from update_users
                     where p.user_id = user_id)
    ORA-00971: missing SET keywordPerhaps you ran something like;
    select * from user_master;
       USER_ID STATUS
             1 A
             2 A
             3 A
    select * from update_users;
       USER_ID
             1
             2
    update user_master p
    set status = 'I'
    where user_id = (select user_id
                     from update_users
                     where p.user_id = user_id);
    2 rows updated
    select * from user_master;
       USER_ID STATUS
             1 I
             2 I
             3 A

  • Need help with SQL for selecting ID where the sequence does not match..

    I have the following dilemma:
    Database contains IDs as follows:
    Incident#, Case#, & Part Sequence#
    example
    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1
    Record 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 2
    Sometimes the user will delete (let's say) Record 2 after creating a new Record 3
    So now the sequencing goes as follows:
    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1
    Record 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 3
    Now there will no longer be a Part_Sequence 2
    Need a SQL to select all records where the maximum part sequence > than the count of Incident_number||'-'||Case_number
    I tried the following:
    select a.incident_number||'-'||a.case_number||'-'||a.part_sequence
    from chsuser.a_compl_summary a
    where a.entry_date >= '01-may-2011'
    and max(a.part_sequence) > count(distinct a.incident_number||'-'||a.case_number)I end up getting a ORA-00934: group function is not allowed here (highlighting on the Max(a.part_sequence) portion.
    Any suggestions/hints
    Thanks

    select  incident_number || '-' || case_number || '-' || part_sequence
      from  (
             select  incident_number,
                     case_number,
                     part_sequence,
                     max(part_sequence) over(partition by incident_number,case_number) max_seq,
                     count(*) over(partition by incident_number,case_number) cnt
               from  chsuser.a_compl_summary
               where entry_date >= DATE '2011-05-01'
      where cnt != max_seq
    /SY.

  • I need help installing Lightroom 5.  I tried the trial and it does not have an uninstall feature.  Thus, I'm trying to activate with my new $9.99 per month subscription and it simply will not work. Very frustrating you already took my money and no results

    I need help installing Lightroom 5.  I tried the trial and it does not have an uninstall feature.  Thus, I'm trying to activate with my new $9.99 per month subscription and it simply will not work. Very frustrating you already took my money and no results, and very difficult to get help.

    Lightroom Trial uninstall wrote:
    Very frustrating you already took my money and no results, and very difficult to get help.
    Just for clarity, "we" haven't taken your money - this is a user-to-user forum, and you're not talking to Adobe.
    Like Rob I'm a Windows user, and - like him - I thought "uninstalling" on Macs was simply a case of trashing the application. Google would seem to concur.
    Not really a Lightroom/Adobe issue, then?

  • I just bought the cretive cloud. For 20 euros per month, and when I dowloaded Illustrator it tells me that the trial has expired and gives me the option to buy. Why?

    I just bought the creative cloud. For 20 euros per month, and when I downloaded Illustrator it tells me that the trial has expired and gives me the option to buy. Why?

    Hi Florencia33,
    Please check if you are signed into the Creative cloud with the correct email ID under which you have subscribed.
    Please refer to the steps as mentioned in the help document:
    Sign out, Sign in | Creative Cloud Desktop app
    Regards,
    Sheena

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • I now have photoshop in cloud for $9.99 per month.

    I now have photoshop in cloud for $9.99 per month. I would prefer Illustrator. Can i cancel or exchange one for the other or is their a package of the two. I already have elements for editing photos

    AL_N_C wrote:
    With PE I can edit videos, do I have the same ability to edit videos in Photoshop CC & Lightroom for 9.99 per month?
    The photographers "special" of Lightroom and Photoshop includes little for videographers.  You can rent Premier Pro for an additional $20 a month, buy Premier Elements or live with the limited video capability of Lightroom. 
    As most users of any recent camera have a video button, it disappoints me that Adobe can't somehow accommodate the amateurs with some sort of limited access to Premier in their "special" price program.

  • Speed Upgrade Advertised For $5 More Per Month Can't Get Any Answers

    On Verizon's website is a speed upgrade to 75/75 for just $5 per month more. When I click on the button to order it it comes up as $10 per month more.On Verizon's Facebook page I posted this 3 times and each time my post was answered quickly and I was told they would look into it and get back to me. No one ever got back to me. The offer is on Verizon's website when I am logged in,
    http://www.verizon.com/home/MLP/quantum75.html?X1=FQU512&CMP=DMC-CVD_ZZ_FD_E_DM_N_X00015

    I can speak from experience on this as I ran into the same situation a couple months ago. A rep. even tried to get me the $5 offer to no success. He could only get it to reflect $10 more. He said something goes on with the system that causes these pricing errors (yet Verizon never fixes them). I was told to wait a week and check the offer again once the system gets updated. I waited a week, checked again and was able to get the offer. My suggestion is to do the same. Wait a week and check again or keep checking daily.

  • Help with updates for CS6

    I need help installing latest updates for CS6.  I have Win 7 and have tried updating from the Help - Updates menu.  The error is:  U43M1D207.

    Thanks for your response.  I am in the United States in So. Arizona.
    Date: Fri, 5 Oct 2012 12:21:45 -0600
    From: [email protected]
    To: [email protected]
    Subject: Help with updates for CS6
    Re: Help with updates for CS6 created by Jeff A Wright in Downloading, Installing, Setting Up - View the full discussion
    Crunkle1 you are welcome to work directly with our support team for guided assistance.  If you go to http://www.adobe.com/ and select Help and Contact Us you should be given the option to contact our support team via telephone.  Which country/region are you in?
    Please note that the Adobe Forums do not accept email attachments. If you want to embed a screen image in your message please visit the thread in the forum to embed the image at http://forums.adobe.com/message/4752605#4752605
    Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4752605#4752605
    To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4752605#4752605. In the Actions box on the right, click the Stop Email Notifications link.
    Start a new discussion in Downloading, Installing, Setting Up by email or at Adobe Community
    For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • I recently signed up for $10.00 per month and haven't been able to download it why?

    I recently signed up for $10.00 per month (Special included Lightroom and Adobe CC) I have continuous tried to download this and I have an Order # but it will not download  Why???

    What is "it" exactly? Lightroom? The Creative Cloud management App?

  • How do I sign up for join Adobe's Photoshop Photography Program for $9.99 per month, giving you acce

    How do I sign up to join Adobe's Photoshop Photography Program for $9.99 per month, giving you access to Photoshop CC, Lightroom, Behance ProSite, and 20GB of cloud storage.

    Cancel old and buy new is the only way I know, but you MAY be able to exchange
    Return, cancel, or exchange an Adobe order

  • I want to buy the special complete for 49.99 per month. if I buy this, how many computers I can install since I have two computers?

    I want to buy the special complete for 49.99 per month. if I buy this, how many computers I can install since I have two computers?
    only one computer or two? Please let me know. 

    Cloud License allows 2 activations http://www.adobe.com/legal/licenses-terms.html
    -Install on a 2nd computer http://forums.adobe.com/thread/1452292?tstart=0
    -Windows or Mac does not matter... 2 on the same operating system, or 1 on each

  • EBS Tables with relation for OBIA Report columns.

    Hi Friends,
    We are trying to find the required EBS Tables for the below tables of HR module report. Please find the tables in OBI query.
    select sum(case when T91397.GROUP_ACCOUNT_NUM = 'CONT EXP' then case when T91707.OTHER_DOC_AMT is null then 0 else T91707.OTHER_DOC_AMT * T91707.GLOBAL1_EXCHANGE_RATE end else 0 end ) as c1,
    sum(case when T91397.GROUP_ACCOUNT_NUM = 'EMP SUPP' then case when T91707.OTHER_DOC_AMT is null then 0 else T91707.OTHER_DOC_AMT * T91707.GLOBAL1_EXCHANGE_RATE end else 0 end ) as c2,
    sum(case when T91397.GROUP_ACCOUNT_NUM in ('GEN PAYROLL', 'MKTG PAYROLL', 'R&D PAYROLL', 'SLS PAYROLL') then case when T91707.OTHER_DOC_AMT is null then 0 else T91707.OTHER_DOC_AMT * T91707.GLOBAL1_EXCHANGE_RATE end else 0 end ) as c3,
    sum(case when T91397.GROUP_ACCOUNT_NUM = 'EMP BENFT' then case when T91707.OTHER_DOC_AMT is null then 0 else T91707.OTHER_DOC_AMT * T91707.GLOBAL1_EXCHANGE_RATE end else 0 end ) as c4,
    sum(case when T91397.GROUP_ACCOUNT_NUM = 'COGS' then case when T91707.OTHER_DOC_AMT is null then 0 else T91707.OTHER_DOC_AMT * T91707.GLOBAL1_EXCHANGE_RATE end else 0 end ) as c5,
    sum(case when T91397.GROUP_ACCOUNT_NUM = 'REVENUE' then case when T91707.OTHER_DOC_AMT is null then 0 else T91707.OTHER_DOC_AMT * T91707.GLOBAL1_EXCHANGE_RATE end else 0 end ) as c6,
    T66755.PER_NAME_MONTH as c7
    from
    W_DAY_D T66755 /* Dim_W_DAY_D_Common */ ,
    W_GL_ACCOUNT_D T91397 /* Dim_W_GL_ACCOUNT_D */ ,
    W_GL_OTHER_F T91707 /* Fact_W_GL_OTHER_F */ ,
    W_STATUS_D T96094 /* Dim_W_STATUS_D_Generic */ ,
    W_MCAL_DAY_D T300914 /* Dim_W_MCAL_DAY_D_Ent */
    where ( T66755.ROW_WID = T300914.MCAL_DAY_DT_WID and T66755.PER_NAME_YEAR = '2009' and T91397.ROW_WID = T91707.GL_ACCOUNT_WID and T91707.DOC_STATUS_WID = T96094.ROW_WID and T91707.DELETE_FLG = 'N' and T91707.ACCT_PERIOD_END_DT_WID = T300914.ROW_WID and (T96094.W_STATUS_CODE in ('POSTED', 'REVERSED')) )
    group by T66755.PER_NAME_MONTH
    select sum(case when T299373.W_EMPLOYMENT_STAT_CODE = 'A' then T299423.HEADCOUNT else 0 end ) as c1,
    sum(T299423.HEADCOUNT) as c2,
    T100027.PER_NAME_MONTH as c3
    from
    W_MONTH_D T100027 /* Dim_W_MONTH_D */ ,
    W_EMPLOYMENT_STAT_CAT_D T299373 /* Dim_W_EMPLOYMENT_STAT_CAT_D */ ,
    W_WRKFC_BAL_A T299423 /* Fact_Agg_W_WRKFC_BAL_A */
    where ( T100027.ROW_WID = T299423.SNAPSHOT_MONTH_WID and T100027.PER_NAME_YEAR = '2009' and T299373.ROW_WID = T299423.EMPLOYMENT_STAT_CAT_WID and T299423.CAL_MONTH_START_DT <= TO_DATE('2013-05-01 00:00:00' , 'YYYY-MM-DD HH24:MI:SS') )
    group by T100027.PER_NAME_MONT
    Of course, if we can go through back track like:
    OBI <-- Infa PLP <-- Infa SILOS <-- Infa SDE <-- SDE Mappletes <-- Source Qualifier <-- Sql Query.
    We are getting no.of tables for single obi table. But, we need only required tables for the above OBI queries for single report.
    Please correct me if wrong and guide me with better approach..
    Thanks in advance.. Appreciate ur inputs here.
    Best Regards,
    Raghu Nagadasari
    Edited by: Raghava Nagadasari on May 1, 2013 5:30 AM
    Edited by: Raghava Nagadasari on May 1, 2013 5:31 AM

    I would say it is part of unit testing; writing ebs query, get results and compare with BI results and some times compare bi query to match some part of criteria.
    I would say just understand the requirements and try to write it, it might take some time but it helps a lot.
    Lineage docs might help some extend to know the source tables, check here
    http://www.cool-bi.com/Ref/Ref.php
    Edited by: Srini VEERAVALLI on May 1, 2013 9:44 AM

Maybe you are looking for

  • Vector and Jtree 4Duke

    hi i am having poblem with my jtree as i am not able to show the object in my vector as a different node {each object is node of my tree} unfortunately they all appear flat in the root, and in sequence{as one node} ?? i have done everything but still

  • Error when importing UTF8 Files into SOD

    I was trying to import a UTF8 csv file into SOD (Lead Object) and I,m running into wierd errors only for some of the records. Mentioned below is the error: "An unexpected error occurred during the import of the following row". It is basically messing

  • Can I turn off tab in the new Safari for ipad?

    I want to turn off the tabs in the new Safari for my iPad 2. I have gone to the settings in Safari and can only select the types of tabs, why can't I turn tabs off?

  • Remaining image color issues in iWEB 2.0.2

    Although images and profiles are now basically treated correctly in ALBUMS in iWEB 2.0.2 this is NOT the case for images in other places. Images dragged to placeholders and directly to pages are severly misstreated. I had missed this in my previous t

  • Ciscowork3.2.1 daemon manager is not working after patch installation

    Ciscowork 3.2.1 daemon manager is not working after patch installation Hi Team Ciscowork 3.2.1 daemon manager is not working after patch installation. C:\Documents and Settings\Administrator>net start crmdmgtd The CiscoWorks Daemon Manager service is