Error when trying to use SUM with COUNT

I have the following query which works fine. However, I need to add another column that is the SUM of the firs column ("OPEN"). I have also included that query but I cannot get it to work. Any help would be appreciated.
SELECT
TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm') as THISDATE,
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
) as OPEN,
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
) as TOTAL
FROM RAW_APP_DATA R, APP_STATE A
WHERE R.RAD_STATUS = A.STATE_ID
AND (R.RAD_SUBMIT_DATE BETWEEN '01-AUG-02' AND '31-JAN-04')
GROUP BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
ORDER BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
(RESULTS)
THISDAT OPEN TOTAL
2002-08 1 37
2002-09 0 40
2002-10 0 33
2002-11 1 25
2002-12 2 22
2003-01 3 25
2003-02 4 101
2003-03 5 99
2003-04 5 85
2003-05 3 69
2003-06 17 90
2003-07 6 57
2003-08 26 89
2003-09 43 117
2003-10 59 110
2003-11 47 67
2003-12 75 80
2004-01 9 9
18 rows selected.
SECOND QUERY (DOES NOT WORK)
SELECT
TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm') as THISDATE,
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
) as OPEN,
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
) as TOTAL,
SUM(
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
)) as "OPEN TOTAL"
FROM RAW_APP_DATA R, APP_STATE A
WHERE R.RAD_STATUS = A.STATE_ID
AND (R.RAD_SUBMIT_DATE BETWEEN '01-AUG-02' AND '31-JAN-04')
GROUP BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
ORDER BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
DESIRED RESULT SET
THISDAT OPEN TOTAL TOTAL OPEN
2002-08 1 37 1
2002-09 0 40 1
2002-10 0 33 1
2002-11 1 25 2
2002-12 2 22 4
2003-01 3 25 7
2003-02 4 101 11
2003-03 5 99 16
2003-04 5 85 21

You are right those are group functions not aggregate. However, if I try to group by with the group functions I get an error (see code).
SELECT
TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm') as THISDATE,
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
) as OPEN,
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
) as TOTAL,
SUM(
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
)) as "OPEN TOTAL"
FROM RAW_APP_DATA R, APP_STATE A
WHERE R.RAD_STATUS = A.STATE_ID
AND (R.RAD_SUBMIT_DATE BETWEEN '01-AUG-02' AND '31-JAN-04')
GROUP BY
TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm'),
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC))
COUNT(decode(A.STATE_DESC, 'Approved', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Concept', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'New', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Pending', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Completed', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rejected', A.STATE_DESC)) +
COUNT(decode(A.STATE_DESC, 'Rescinded', A.STATE_DESC))
ORDER BY TO_CHAR(TRUNC(R.RAD_SUBMIT_DATE, 'MM'), 'yyyy-mm')
ORA-00934: group function is not allowed here
Do I group by the columns individually?

Similar Messages

  • Error when trying to use LogMiner with Oracle 8.1.6.0.0

    Hi everybody,
    I'm trying to use LogMiner with Oracle 8.1.6.0.0. When I execute the following code with SQL*Plus, I have an error.
    BEGIN
    DBMS_LOGMNR.START_LOGMNR
    (options =>
    dbms_logmnr.dict_from_online_catalog);
    END;
    The error displayed by SQL*Plus is:
    PLS-00302: 'DICT_FROM_ONLINE_CATALOG' must be declared.
    Please, how to solve this problem?
    Thanks you in advance for your answers.

    user639304 wrote:
    Hi everybody,
    I'm trying to use LogMiner with Oracle 8.1.6.0.0. When I execute the following code with SQL*Plus, I have an error.
    BEGIN
    DBMS_LOGMNR.START_LOGMNR
    (options =>
    dbms_logmnr.dict_from_online_catalog);
    END;
    The error displayed by SQL*Plus is:
    PLS-00302: 'DICT_FROM_ONLINE_CATALOG' must be declared.
    Please, how to solve this problem?
    Thanks you in advance for your answers.Looking at the 8.1.7 doc set (the oldest available on tahiti) I get no hits when searching for 'dict_from_online_catalog'. Searching the 9.2 doc set turns up a reference. Looks like you are trying to use an option that isn't available in your version of Oracle.

  • "500 internal server error" when trying to use F4 help in the variable sele

    Hi Experts,
    I am getting "500 internal server error" when trying to use F4 help in the variable selection screen (in WAD).
    How could this be resolved?
    Quick reply would be very helpfull.
    Thanks in advance !!

    It seems you are using wrong client ID. Make sure your logon pad has right details. You should verify this with your basis team.
    If the problem persists then try re-installing. But before you do that you can execute sapbexc.xla which is in the c:\program files\sap\bw. Type c:\ in cell c3 and click "start button". Any red flag means you have wrong version dll/ocx on your local drive, in that case you should reinstall with right patches.
    if this solution helps u then pls assign points

  • Runtime error when trying to use Thinkvantage system updater

    I get a runtime error when trying to use the Thinkvantage system updater.Have tried it numerous times and this is the exact message:
    "Runtime error!
    Program:C:\Program Files\Lenovo\System Update\tvsu.exe
    This application has requested the Runtime to terminate it in an unusual way.
    Please contact the application's support team for more information."
    Can somebody please help me to get the Thinkvantage system updater working properly?
    Thanks-George
    This issue has since been resolved.Thanks-G

    I'm getting the same error.   I tried reinstalling system updater but it didn't help.

  • Why do I get this error when trying to use my bluetooth headset as a listening device? There was an error connecting to your audio device. Make sure it is turned on and in range. The audio portion of the program you were using may have to be restarted.

    Why do I get this error when trying to use my bluetooth headset as a listening device? There was an error connecting to your audio device. Make sure it is turned on and in range. The audio portion of the program you were using may have to be restarted.

    I may have already resolved this issue buy removing the device from my computer and re-pairing it. It is currently working just fine.

  • I get the following error when trying to use the itunes store "your apple id has been disabled"

    I get the following error when trying to use the itunes store "your apple id has been disabled".  My account was disabled when someone else had been using it without my knowledge.  I changed my apple id password and the apple id is still fine, but itunes has it disabled.  I verified that the computer is authorized for this apple id.  What to do now?

    Welcome to the Apple Community.
    Contact Apple through iTunes Store Support

  • Error 4002 when trying to use iMatch with mac

    I have been trying to use iMatch with my mac and I continue to receive error 4002

    user639304 wrote:
    Hi everybody,
    I'm trying to use LogMiner with Oracle 8.1.6.0.0. When I execute the following code with SQL*Plus, I have an error.
    BEGIN
    DBMS_LOGMNR.START_LOGMNR
    (options =>
    dbms_logmnr.dict_from_online_catalog);
    END;
    The error displayed by SQL*Plus is:
    PLS-00302: 'DICT_FROM_ONLINE_CATALOG' must be declared.
    Please, how to solve this problem?
    Thanks you in advance for your answers.Looking at the 8.1.7 doc set (the oldest available on tahiti) I get no hits when searching for 'dict_from_online_catalog'. Searching the 9.2 doc set turns up a reference. Looks like you are trying to use an option that isn't available in your version of Oracle.

  • Keep getting VncViewer.class not found error when trying to use Windows 7

    Greetings,
    I have no issue accessing the OVM Manager 2.2 with OEL 5.4 x86_64 with the latest Java release from ULN. But when I use a Windows 7 client ( x86) with the Sun Java 6 Update 18 I get the following error when trying to access the Console of a VM Guest:
    Java Plug-in 1.6.0_18
    Using JRE version 1.6.0_18-b07 Java HotSpot(TM) Client VM
    User home directory = C:\Users\deverej
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    load: class VncViewer.class not found.
    java.lang.ClassNotFoundException: VncViewer.class
         at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
         at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)
    Caused by: java.io.IOException: open HTTP connection failed:http://141.144.112.202:8888/OVS/faces/app/VncViewer/class.class
         at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
         at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
         at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         ... 7 more
    Exception: java.lang.ClassNotFoundException: VncViewer.class
    I am curious fi I should use only a specifc Java Engine with IE 7 or the latest Firefox browers.

    Same issue to with Windows XP SP3 x86 with Java Runtime Enviornment 1.5.0_15
    J2SE Enviornment 5.0 Update 15
    Java 6 Update 17

  • Why do I get an error when trying to use a link in the forum?

    I just tried to use the link that Varad offered in Redirect certain users with login procedure and I got an error:
    The specified thread [0] was not found.
    I got the same thing when trying to use a similar link a couple of days ago. They sound like something I might benefit from, but I can' get to them.
    The link URL looks like Re: logon username determines page that opens, how can I accomplish this?
    Any ideas?
    Thanks,
    Gregory
    P.S. I'm using Firefox 3.0.4

    Tony,
    That's what I thought, but apparently it worked for Stefan. If you go to Stefan's post (first link above) do you also see the same link as I have attempted to copy? In Stefan's post, do you see the question mark in a diamond?
    Thanks,
    Gregory

  • List of values failure error when trying to use dynamic data values

    Hi there,
    I have a user who is experiencing problems when trying to use dynamic values in a report.  Whenever he tries to insert dynamic parameters he gets the following error message:
    Prompting failed with the following message: 'List of Values failure: Failed to get values.  [Cause of error: Access is denied.]  Error Source: prompt.dll  Error Code: 0x8004380D
    He even opened the sample report - prompting.rpt - that is included with CR and gets the same error.
    We are using Crystal Reports XI Release 2 ver. 11.5.11.1470.
    Any help would be appreciated.

    Please excuse my ignorance of the product.  I've had this problem dropped in my lap and I know practically nothing about Crystal Reports.  In doing some digging it appears to me as if the BusinessObjects Enterprise software may not be installed properly, if at all.  In the programs menu under the BusinessObjects XI Release 2 folder I see a BusinessObjects Enterprise folder, but the only icon listed in that folder is Software Inventory Tool.
    Is the BusinessObjects Enterprise software a separate install from Crystal Reports or is it bundled together?  I talked with the tech that did the install and he said that all he had was the Crystal Reports install media.

  • Pop-up errors when trying to use FaceBook on Sarafi 4 on Windows

    Hi there.
    When trying to use Safari on Windows, I get an annoying pop-up whenever I try to use chat on FaceBook and it says something about MIME type not recognised and pluggin errors. I have installed the latest flash but it keeps happening - is there another plug-in I need to reinstall?

    Here is a link to the info on how to access the 4200 set up pages and how to do Port Forwarding with it
    http://portforward.com/english/routers/port_forwarding/Siemens/4200/iChat.htm
    Use the Access info and then see if you have it doing UPnP to open the ports.
    If it is then the Port Forwarding does not need setting.
    Next, if you did originally set it to do Port Forwarding this should have pointed to an IP (The one your computer has/had)
    Check the Port Forward that is set is pointing to the IP the computer has now by Looking in System Preferences > Network
    QUite a way done the log your end suddenly switches the port it sends the SIP part of the invite on
    INVITE sip:user@rip:61042 SIP/2.0
    Via: SIP/2.0/UDP sip:60442;branch=z9hG4bK672a7283709f480e
    Max-Forwards: 70
    To: "u0" <sip:user@rip:61042>
    From: "0" <sip:user@lip:16402>;tag=2100237526
    Call-ID: 5c6e32e2-2788-11dd-904a-8c2872d74012@lip
    CSeq: 1 INVITE
    Contact: <sip:user@sip:60442>;isfocus
    User-Agent: Viceroy 1.3
    Content-Type: application/sdp
    Content-Length: 744
    This is not an iChat port and it messes up where iChat then says to send the Video and Audio data.
    The log from the other end implies the ports are not even open.
    10:42 PM Wednesday; July 9, 2008

  • Program error when trying to use the clone stamp tool - PSE 8

    When trying to use the CLONE STAMP TOOL, getting the following:  "Could not use the clone stamp tool because of a program error".
    Runnng PSE 8 on Windows XP/SP3.  I purchased the key to have a full version, versus the 'trial version'.  I also have Photo Essentials 3 installed and have used it without any problems.
    Any suggestions?

    I figured it out - it was ID 10 T error...ugh.
    Was following along in a book and blindly did what it said....was forgetting to hit the 'alt' key when first defining the area to clone....
    However, it was kind of a confusing error message - something like "clone area not defined" would be more of a help.
    thanks.

  • Error when trying to reinstall MBAM with SCCM

    We have SCCM 2012 R2 installed and I installed MBAM 2.0 SP1 with all the components on the same server.  Well that was a mistake as the website for MBAM took over and SCCM communication with all the clients was broken.  So I found a TechNet article
    that said I should only install the SCCM Integration Feature of MBAM and then install the other components on another VM.  I then proceeded to uninstall all the MBAM components and SCCM started working properly again.  I then went to reinstall just
    the SCCM integration feature of MBAM and I got the error that SCCM Objects already installed.  The resolution says "One or more components of the MBAM System Center Configuration Manager Objects have
    already been installed.  If the objects were previously installed then they were intentionally not removed. Please refer to the System Center Configuration Manager documentation on how to properly remove the installed MBAM System Center Configuration
    Manager objects. More information can be found at:
    http://go.microsoft.com/fwlink/?LinkID=276922.
    I went to that link and did the removal steps and I still get the error when trying to reinstall it.  Why am I still getting the error message?

    You have to remove the MBAM Supported Computers collection, The two BitLocker configuration items, the BitLocker configuration baseline, and the MBAM reports in CM, including the folder called MBAM (you will have to go to your SSRS server URL for your
    reporting services point to be able to delete the folder).

  • I am getting the ssl error when trying to use launchpad on ssl, i can access adminui through ssl with no errors but launchpad says "unable to find valid certification path to requested target"

    Hi I desperately need help  to fix this error. I installed Adobe LCES4 with ssl enabled and i can access the adminui and workspace on the browser but he problem is when i try connecting to launchpad using https on the server even doing the simple thing like converting document to pdf throws the following error.
    any help will be appreciated
    DSC Invocation Resulted in Error: class com.adobe.idp.DocumentError : javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target : javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    thanks

    We tried adding certificate in trustore.jks file, but it was not successful.
    What error you are getting while importing the certificate?
    Just perform below steps once:
    Download required certificate first
    Run CMD as administrator> move to SUP_HOME\Servers\UnwiredServer\Repository\Security
    Paste this syntex.
    keytool -importcert -alias customerCA -file <certificatefilename>.crt -storepass changeit -keystore truststore.jks -trustcacerts

  • Error when trying to use (GUI Wizards) on Table with BLOB, CLOB columns.

    I enjoyed watching the demo of ODP.NET/VS 2005 Environment where you can just drag the new command builders, data sets, etc.. but when I try this with a table that contains a BLOB and CLOB column it returns an error and basically cannot build the SQL needed to process these field types.
    I would assume it could do this natively since it is somewhat of a primitive type. I also tried to point it to a Stored Proc that returned a blob and it caused an error when building the SQL.
    So it appears it is not possible to use the GUI data access wizards for these column types. I can use them in code with the ODP.NET with no problems but it would be nice to be able to utilize the GUI Command Builders, etc...

    blob and clob are not supported i guess. oracle is a bit sluggish when it comes to VS and MS products!

Maybe you are looking for

  • I life 06 has stopped Safari being able to open this page and my bank?

    I am having to write this from IE as since installing I Life06 Safari has not been able to go to my internet banking sites. The message unable to establish a secure connection comes up. IE still works fine. Also I can't log onto the apple discussion

  • Is there any options to know what is the particular field that has been changed or updated in AR invoice?

    Hi... Is there any option to know what is the actual field that has been updated / changed in the AR Invoice document. ADOC and ADO1 Contains the history of the updated documents ..... but i need what is the exact field that has been changed....? Is

  • URL in PA20/30

    We are curretnly implementing an EDRMS system and there is a requirement to place a dynamic URL in PA20/30 that links through to the new system and has the parameter of the personnel number you are currently looking at. eg http://EDRMS.company.com/pe

  • Loving Flex Time

    For the past few days I've been editing vocals for the first using flex time for a remix. the original tempo of the song was around 89-90's. I wasn't provided the original tempo. But my remix is 120 I imported the vocals put the tracks on Polyphonic

  • YouTube thumbnails not visible on Safari

    The thumbnails on YouTube are not visible on Safari. The videos play fine. The automatic seach suggestion isn't working. Also, I can't expand the video player to the medium size; I can watch in full screen and the smaller video player size. Everythin