SQL in Question actually. Select the items for all 12 months

I am creating a notification request where I SUMMARIZED all of the amounts in the database for all 12 mount and come up with a result even if it isn't a amount totaled. I created a table called monthsInYear that has the ID (unique identifier) 1-12 and the months of Jan - Dec. I want SUM to the amount per month and arrived to the top with 12 results (one per month).

I tried the query below, but sometimes with only 1 month and all amounts amounted to him.

March484714.13

I use:

SELECT monthsInYear.month, IFNULL (SUM (income.amount), 0) AS amount

OF monthsInYear

Income ON EXTRACT(MONTH FROM income.dateAdded) = monthsInYear.monthID LEFT OUTER JOIN

WHERE income.orgID = 10031

AND the YEAR (income. DateAdded) = '2011'

ORDER BY EXTRACT (MONTH FROM income.dateAdded) CSA

Can someone tell me what I am doing wrong. I much prefer something like:

January 3000

February 3000

March 4000

April 0

Maybe 5000

June 6000

July 5465

....

But when I run the present, it gives me total for only the months which have in total and not 0 for those that go up as null. Any ideas?

....

Also tried

SELECT m.month, IFNULL (SUM (i.cost), 0) AS amount

I have getExpenses LEFT OUTER JOIN monthsInYear m

ON m.monthID = EXTRACT (MONTH FROM i.dateAdded)

WHERE orgID = 10031

AND YEAR (i.dateAdded) = '2011'

GROUP BY m.month

ORDER BY EXTRACT (MONTH FROM i.dateAdded) CSA

There are two problems. First of all, in your join tables are reversed. A LEFT JOIN returns all the records in the left table (spending) even if there is no matching record in the table to the right. What you want, it's the opposite. If the month table should be on the left side of the JOIN:

...

OF monthsInYear m LEFT JOIN getExpenses i m.monthID = EXTRACTION (i.dateAdded MONTH)

Second, when there is no corresponding record in the expense, the column values will be null. So as soon as you use one of the fresh fields in your WHERE clause, that is to say

WHERE i.orgID = 10031

AND YEAR (i.dateAdded) = '2011'

... these missing documents are deleted, because a null value is never equal to what it is. So you are denying the outer join altogether. You must move these conditions in the JOIN clause instead:

SELECT m.month, IFNULL (SUM (i.cost), 0) AS amount

MonthsInyear LEFT OUTER JOIN getExpenses m I have

ON m.monthID = EXTRACT (MONTH FROM i.dateAdded)

AND i.orgID = 10031

AND YEAR = 2011 (i.dateAdded)

GROUP BY m.month

ORDER BY m.month

Tags: ColdFusion

Similar Questions

  • Select the options for ALL but some in OBIEE prompt with a single click

    Hello guys,.

    I have the below requirement

    I have a prompt that displays the payment terms.

    On the result - 3 payment terms are the terms of payment we and the rest are Global.

    A user will select these 3 conditions of payment of the United States or the reset of the (Global) payment terms, but not all.

    Y at - it somehow I can create an option that selects all terms of payment with one click (as the option all columns)

    also, I'm trying to use all of the columns, which is to select all the columns including US and global, but once the user selects all the column option - the user is not able to selectively disable certain values.

    Is there a work around for this?

    Please let me know because this would be a great help for me.

    Thank you

    Why don't make you a second guest of the column where you add the CASE WHEN to produce the 2 types of terms (US & Global)?

    Then using the "limited by" you auto-filtre the actual list of terms of payment based on the first selection and is to meet your requirement to select all of the USA or Global all with just 1 click.

    The user you want to select just 1 term given? Just ignore the first field of the prompt with the groups and directly select the one required in the second field.

  • Scaling of image directly by selecting the item in the Assembly?

    Hi all

    I want to put a video/image that is on my calendar, I want to know is, is it possible to simply select the item in the timeline and resize it in the program with the mouse (click and drag) monitor?  Currently, what I have to do is,

    a. Select the item in the timeline

    b. Select again the request in the control effects

    c. the scale with the mouse in the program monitor

    pls help,

    I'm working on first pro 2015.

    Kind regards

    Make sure the clip is visible in the program monitor

    Double-click on the screen and a bounding box will appear.

  • I have problems, adding comments using Adobe reader DC on my pro 3 surface. I can select the circle for example, but when I try to draw the circle nothing happens and the screen just scrolls in the direction I move the pointer?

    I have problems, adding comments using Adobe reader DC on my pro 3 surface. I can select the circle for example, but when I try to draw the circle nothing happens and the screen just scrolls in the direction I move the pointer?

    Hey paulc6148125,

    Please try the mode settings different button in Adobe Acrobat Reader DC-> leModifiermenu-> preferences-> general categories.

    Kind regards

    Nicos

  • cannot open the item for creating adobe 11 on my MacBook Pro? that I buy it from the App Store? Help, please

    cannot open the item for creating adobe 11 on my MacBook Pro? that I buy it from the App Store? Help, please

    its said that its currently not available

    I have so much work account on this program, please help

    Make sure that your computer meets the requirements for the software you have purchased.  If this isn't the case, you will need to see about getting a refund.

    If she does not meet requirements, you must talk to the seller your issue with the product that they have you sold.

  • How to enable the CACHE for all LOB data

    Hello

    I want to activate the CACHE for all LOB in my database - 10.2.0.4

    Does anyone has generic script to activate the cache for all TRADES

    Thank you

    You should be able to write some dynamic SQL code. This will set each BUSINESS in the current schema CACHE

    DECLARE
      l_sql_stmt VARCHAR2(4000);
    BEGIN
      FOR lobs IN (SELECT * FROM user_lobs)
      LOOP
        l_sql_stmt :=
          'ALTER TABLE ' || lobs.table_name ||
          ' MODIFY LOB( ' || lobs.column_name || ' ) (cache)';
        execute immediate l_sql_stmt;
      END LOOP;
    END;
    

    Justin

  • How to extract the ddl for all databases of links?

    DB: oracle11gr2

    Friends,

    I can get including db link the package DBMS ddl but could not able to find a way to extract the ddl for all the database link and the coil in a file recreate them in the future?

    Tried searching on OTN but no luck, if someone shares how them spool or point me to a particular forum that will be great.

    Thank you

    We may also use something simple, select as below to extract the ddl

    Select dbms_metadata.get_ddl ('DB_LINK', db_link, owner) vSQL of

    dba_db_links

    /

  • Can I get the videos for all of the concepts of photoshop learning?.

    I have an account paying adobe... Can I get the videos for all of the concepts of photoshop learning?.

    All I see is that links like

    CC Photoshop tutorials | Learn how to use Photoshop CC

    Above links are available even without an account.

    Should I have any extra advantage to access additional videos (as in lynda.com where they have the series of videos that explain how to do something with explanation of the concept)

    Originally, there was a selection of 'members only' videos on the Adobe Web site. But this project was abandoned and all content has been made public.

  • find the ddl for all index

    Hello
    on the 11g on Win 2008 R2

    How to find the ddl for all index built on MY_VW?
    Thank you.

    You can use DBMS_METADATA for this:

    SELECT DBMS_METADATA.GET_DDL
           ( 'INDEX'
           , index_name
           , owner
           )
    FROM   all_indexes
    WHERE  table_name  = ''
    AND    table_owner = ''
    ;
    
  • How to get the IP Address of the Console for all my guests

    How to get the IP Address of the Console for all my guests

    a simple...

    Get-VMHost | Select Name, @{N="ConsoleIP";E={(Get-VMHostNetwork $_).ConsoleNic | ForEach{$_.IP}}}
    
  • How to change the password for all users in the database

    Hi buddies!

    Could someone tell me how to change the password for all users in the database? I want to set the same password for all users.

    Thank you.

    Nith

    Published by: user645399 on March 1, 2011 14:23

    Write the file spooling
    as

    Make sure that all profiles has password_verify_function with a NULL value

    then

    Select 'edit user' | username: ' identified by ;' from dba_users;

    you will get the output... you just run.

  • Get the DDL for all tables in a schema;

    Hello

    I tried to get the DDL for all tables under my own diagram "A". Here are the steps I've tried, but in vain I
     1. logged in as a user A 
    2. And the ran query 
              
    SELECT DBMS_METADATA.get_ddl ('TABLE', 'XYZ')
    FROM user_tables
          
    o/p
    (HugecloB)
    
    {code}
    
    Any idea how i can get the DDL for all the tables under my own schema ?
    
    
    Thank you so much!
    
    Edited by: user642297 on Feb 4, 2011 12:05 PM
    
    Edited by: user642297 on Feb 4, 2011 12:05 PM
    
    Edited by: user642297 on Feb 4, 2011 12:05 PM
    
    Edited by: user642297 on Feb 4, 2011 12:07 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        

    Your idea is good, you missed only to use the correct table name:

    SELECT DBMS_METADATA.get_ddl ('TABLE', table_name)
    FROM user_tables;
    

    Concerning

  • Whe trying to update ios to ios 9.3 9.2.1 come error 3194 give me the solution for all I phone and ipads

    Whe trying to update ios to ios 9.3 9.2.1 come error 3194 give me the solution for all I phone and ipads

    Try some suggestions here: If you see error 3194, error 17, or "this device is not eligible for the requested build" in iTunes - Apple Support

  • How to permanently change the font for all emails color

    How can I change the color of the font for all my emails constantly?

    E-mail address is removed from the privacy *.

    Hello Msmouser,

    What mail client do you use?
    If you use Outlook, I suggest to look at this article:
    If you use your web mail from Verizon, I would say that to visit the Verizon Mail support page:
    If you use Windows Live Mail, please visit:
  • can not install the software for all in one photosmart 2610xi of disc of windows 7 pc

    I can't install the software for all in one photosmart 2610xi of disc of windows 7 pc.  Goes so far then stops and says cannot use the command "run as".  I am the administrator and logged as such.  I would like to use the software provided with to send faxes and others.  I can use the printer since the buttons on the printer and it prints from all programs... I just wanted to use this software.  Any suggestions?

    Thank you

    Hello

    The installation disk supplied with the printer is not compatible with Windows 7, as the device was manufactured prior to release of Windows 7.
    No matter which compatible OS are registered on the CD...

    A newer version of the software for Windows 7 can be downloaded from the HP site.

    Before installing the software, be sure to follow the steps below:

    1. Enter the control panel > devices and printers.
    2. Right-click on the icon Photosmart 2610 and lick to withdraw an instrument.
    3. Disconnect the USB cable between the printer and restart your PC.
    4. Follow the below installation, do not connect USB until prompted to do so during the installation of the software:
      http://h10025.www1.HP.com/ewfrf/wc/softwareDownloadIndex?softwareitem=MP-76831-1&cc=us&DLC=en&LC=en&OS=4062&product=421134&sw_lang=

    Kind regards

    Shlomi

Maybe you are looking for