Subquery in the select clause and not "a group by expression" error.

Hi all
I hope someone out there can help me out with this one. I have a sql query that performs a subquery in the select case combined with an aggregate function and gives me a "not a group by expression.

I created a simplified example
 SELECT COUNT(*)                     ,
  ai.invoice_num invoice_number      ,
  ai.description invoice_description ,
  (SELECT poh.po_header_id
       FROM po_headers poh ,
      po_distributions pod
      WHERE pod.po_distribution_id = aid.po_distribution_id
    AND pod.po_header_id           = poh.po_header_id
    ) po_number
     FROM ap_invoice_distributions aid ,
    ap_invoices ai
    WHERE ai.invoice_id = 1476932
  AND aid.project_id    = 8608   
  AND aid.task_id       = 462202  
  AND ai.invoice_id     = aid.invoice_id
 GROUP BY ai.invoice_num,
                ai.description;
I'm sure he expected me to add the po_number to the group by clause, but this does not work and gives the error "invalid identifier".

Can someone suggest a way for a new concert the query so that I can add po_number to my education by clause.

Kris

You should try either:

SELECT COUNT (*),
AI.invoice_num invoice_number,
have. Description invoice_description,
(SELECT poh.po_header_id
OF po_headers poh,.
pod po_distributions
WHERE pod.po_distribution_id = aid.po_distribution_id
AND pod.po_header_id = poh.po_header_id
) po_number
HELP ap_invoice_distributions.
ap_invoices AI
WHERE ai.invoice_id = 1476932
AND aid.project_id = 8608
AND aid.task_id = 462202
AND ai.invoice_id = aid.invoice_id
Ai.invoice_num GROUP,
have. Description, aid.po_distribution_id;

or

SELECT COUNT (*),
AI.invoice_num invoice_number,
have. Description invoice_description,
MAX ((SELECT poh.po_header_id
OF po_headers poh,.
pod po_distributions
WHERE pod.po_distribution_id = aid.po_distribution_id
AND pod.po_header_id = poh.po_header_id
po_number))
HELP ap_invoice_distributions.
ap_invoices AI
WHERE ai.invoice_id = 1476932
AND aid.project_id = 8608
AND aid.task_id = 462202
AND ai.invoice_id = aid.invoice_id
Ai.invoice_num GROUP,
have. Description;

Tags: Database

Similar Questions

  • Anyone know if you can use FTP, when you save, just save the selected file and not all images and cs

    Someone knows If you can use FTP, When you save , just Save the selected file and not all the images et CSS includes ...

    What?  Can you please rephrase your question in order to understand what you're asking?

    If you ask how a file on the remote site via FTP without FTPing any dependent files?  That the answer is Yes, you can do this by changing the SITE > dependent files: option in the PREFERENCES to enable the option "prompt on put/check-in."  The next time you download a file, you will be asked if you want to also download dependent files.  If you say NO and check the don't ask again option, then you will always simply load the file and not the dependents. You can change it back at any time by changing the preferences of this setting.

  • Listagg function gives ORA-00979: not a GROUP BY expression error

    Hello

    I have an environment that supports the Listagg function. Suite works perfectly:

    Select task_code, LISTAGG(ename||) e ('| role |') (',',') WITHIN GROUP (ORDER BY ename) as employees

    team

    where task_code = '01.07.05'

    Task_code group

    However, this is just a test request, the real is a little wider and I can't get the function works, I get ORA-00979: not a GROUP BY expression error.

    Here's my query (the column names are in Dutch, but that shouldn't really be a problem):

    SELECT distinct op_sod.sod_code, op_sod.sod_omschr_lang, op_ood.ood_code, op_ood.ood_omschr_lang, op_activiteit.act_code, op_activiteit.act_omschr_lang, op_taak.taak_code, op_taak.taak_omschr_lang, op_afdeling___master.afd_code, op_taak.belmo, op_taak_j.planning_la,

    LISTAGG (op_ploeg.wn_naam |) ' ('| op_ploeg.rol |') (',',') WITHIN GROUP (ORDER BY op_ploeg.wn_naam) as employees.

    "Write subtaak/mijlpaal toe."

    op_teamplanning.subtaak_mijlpaal as subtaak_of_mijlpaal,

    op_teamplanning.subtaak_omschr | -case when op_teamplanning.subtaak_mijlpaal = 'BELMO Mijlpaal' then ' (BRUNO mijlpaalnr: ' | nvl (op_teamplanning.nummer, 0) |) ')' other ' ' end

    as subtaak_mijlpaal_omschrijving, op_teamplanning.deadline as date limit, op_teamplanning.status as status,

    trim (both

    case when op_teamplanning.vlag1 = 'Geen' and op_teamplanning.vlag2 = 'Geen' and op_teamplanning.vlag3 = 'Geen' and op_teamplanning.vlag4 = 'Geen'

    and op_teamplanning.vlag5 = 'Geen' or op_teamplanning.vlag1 is null and op_teamplanning.vlag2 is null and op_teamplanning.vlag3 is null

    op_teamplanning.vlag5 is null and op_teamplanning.vlag4 is null then 'Geen '.

    Another pad (both case when op_teamplanning.vlag1 = 'Geen' then "else trim (both from op_teamplanning.vlag1) end) |

    trim (both case when op_teamplanning.vlag2 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag2) end) |

    trim (both case when op_teamplanning.vlag3 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag3) end) |

    trim (both case when op_teamplanning.vlag4 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag4) end) |

    trim (both case when op_teamplanning.vlag5 = 'Geen' then "another ',' | trim (both from op_teamplanning.vlag5) end) end) as Beleidsvlaggen,

    op_teamplanning.naam_verantw as quotation, op_teamplanning.subtaak_id as subtaak_id, nvl (op_teamplanning.nummer, 0) as Nummer, nvl (op_teamplanning.regelgevingsagenda, 'Nee') as

    Regelgeving, op_teamplan_subsubtaak.subsubtaak_submijlpaal as subsubtaak_submijlpaal, op_teamplan_subsubtaak.subsubtaak_id as subsubtaak_id, op_teamplan_subsubtaak.subsubtaak_omschr

    like subsubtaak_omschr, op_teamplan_subsubtaak.deadline, sub_deadline, op_teamplan_subsubtaak.status as sub_status, op_teamplan_subsubtaak.naam_verantw as naam_verantw

    Of...

    WHERE THE...

    Group of op_sod.sod_code, op_sod.sod_omschr_lang, op_ood.ood_code, op_ood.ood_omschr_lang, op_activiteit.act_code, op_activiteit.act_omschr_lang, op_taak.taak_code, op_taak.taak_omschr_lang, op_afdeling___master.afd_code, op_taak.belmo, op_taak_j.planning_la


    Can someone tell me the reason for this error?

    Thanks in advance!

    Kind regards

    NDG

    NDG123 wrote:

    I don't really understand your other question:

    Is below for example, a group of expression?

    op_teamplanning.subtaak_mijlpaal

    After some additional research:

    The group by mistake is not appear anymore when I delete all fields after the listagg field, that might be a clue to the solution.

    It is not difficult to understand. You can have other columns not aggregated in your projection on the side of those listed in the group by expression.

    The reason for ORA-01489 is that the resulting string will become long and exceeds 4000 bytes.

    You will find several solution in this forum.

    For example

    Re: Listagg function excdding 4000 characters

  • Not a group by expression error

    Hello

    Can you please tell me why the query below is to launch one isn't a group by expression error

    Select count (*),

    TO_CHAR (date, "YYYYMM") table

    To_char (date, 'yyyymm') group;

    Basically I want a count by month.

    Help, please

    Thank you

    Check the status of Tom on this thread, which seems similar to your problem:

    Ask Tom & quot; Group By clause & quot;

  • ORA-00979: not a GROUP BY expression error

    Hi all

    I added a GROUP BY clause that includes all expressions of individual column listed.
    I don't know why this error occurs. ?
    How could I solve this problem?


    SELECT site_to_data_source_lane_v.site_id,  
            site_to_data_source_lane_v.site_lane_id,
            traffic_record.record_id,
            traffic_record.datetime,
            NVL(traffic_class.v_class, 0),
            NVL(SUM(traffic_status.status_code), 0) vehicle_status_count,  
            NVL(COUNT(traffic_error.error_code), 0)  vehicle_error_count ,
            NVL(site_to_data_source_lane_v.site_lane_id, 0) ,
            NVL(traffic_status.status_code, 0),
            NVL(traffic_error.error_code, 0)
        FROM traffic_record
        LEFT OUTER JOIN traffic_class
          ON traffic_record.record_id = traffic_class.record_id    
        LEFT OUTER JOIN traffic_error
          ON traffic_record.record_id =traffic_error.record_id              
        LEFT OUTER JOIN traffic_status
          ON traffic_record.record_id =traffic_status.record_id         
        JOIN site_to_data_source_lane_v
          ON traffic_record.data_source_id = site_to_data_source_lane_v.data_source_id
         AND traffic_record.lane = site_to_data_source_lane_v.data_source_lane_id
        JOIN edr_rpt_tmp_report_lanes
          ON site_to_data_source_lane_v.site_lane_id = edr_rpt_tmp_report_lanes.site_lane_id
        JOIN edr_rpt_tmp_report_classes
          ON NVL(traffic_class.v_class, 0) = edr_rpt_tmp_report_classes.class_id
        JOIN edr_rpt_tmp_inclusion_table
          ON TRUNC(traffic_record.datetime) = TRUNC(edr_rpt_tmp_inclusion_table.date_time)
       WHERE site_to_data_source_lane_v.site_id = 32
         AND traffic_record.datetime >= to_timestamp('07/01/2008 00:00:00', 'mm/dd/yyyy hh24:mi:ss')
         AND traffic_record.datetime <  to_timestamp('07/31/2008 00:00:00', 'mm/dd/yyyy hh24:mi:ss') 
         GROUP BY site_id,                        
                              site_lane_id,
                              record_id,
                              date_time,
                              v_class,                
                              status_code,
                  error_code;
                  

    You choose: -.

    site_to_data_source_lane_v.Site_ID,
    site_to_data_source_lane_v.site_lane_id,
    traffic_record.record_id,
    traffic_record. DateTime,
    NVL (traffic_class.v_class, 0),
    NVL (Sum (traffic_status.status_code), 0) vehicle_status_count,
    NVL (Count (traffic_error. (Error_code), 0) vehicle_error_count,
    NVL (site_to_data_source_lane_v.site_lane_id, 0),
    NVL (traffic_status.status_code, 0),
    NVL (traffic_error.error_code, 0)

    But you are a grouping by

    Site_ID,
    site_lane_id,
    record_id,
    Date_Time,
    v_class,
    status_code,
    Error_code

    Quite a few differences...

  • CM1415fnw-when scanning in color-message "the selected folder is not writable" - scan OK in black and white

    1 HP LaserJet CM1415fnw

    2 mac OSX 10.7.4

    3. message: "the selected folder is not writable" when try to scan in color, scans OK in black and white

    Make sure the registration color scans at is not read-only.  You can do this by right-clicking on the folder and then select Properties.  Ther will be a box with the unalterable words beside him.  Make sure that the check box is disabled.  If the box has a check or anything in this document, click it until there is nothing in the box.  Let me know what happens.

  • When I select Help and support icon, I get an error message indicating that the feature could not start.

    help and support does not work

    When I select Help and support icon, I get an error message indicating that the feature could not start.

    I use a Vista 32 bits on a HP computer operating system model number m8300f.

    In addition, I bought a copy of Win 7, but who could not load freezing during installation.

    Hello

    Try to run the command in the elevated command prompt, follow the steps below, it could help us solve the problem.

    1. open the start menu, click programs principally made, select accessories.
    2. right click on command prompt, and then click "run as administrator ".
    3. type the following commands in the DOS prompt window and press ENTER at the end
    of each line:

    REGSVR32 MSXML3. DLL/U
    REGSVR32 MSXML3. DLL
    REGSVR32 MSXML6. DLL/U
    REGSVR32 MSXML6. DLL

    (At the elevated command prompt command should not give us any error).

    Restart the computer and try to access help and Support.

    For the problem of installation of windows 7.

    We would like to get more information about you to help solve your problem. You better, please answer the following questions.

    1. How did you start the installation process?

    2. you perform a new installation or an upgrade?

    3. what type of drive you are using for installation?

    4. at what stage of the installation has it stopped?

    5. have you received an error message?

    First of all, I would say that you disconnect external devices connected to the computer except the keyboard and mouse.

    If you have performed an upgrade suggests to restart the computer and you will be prompted for a roll back option.

    Once you're on the office suggests to run Upgrade Advisor and check what needs to be done before you start the upgrade.

    Before you begin the upgrade process to ensure that your computer meets the condition of equipment to install Windows 7 and check on the website of manufacturer computer if the computer is good to run windows 7 or not.

    Installing and reinstalling Windows

    http://Windows.Microsoft.com/en-us/Windows7/installing-and-reinstalling-Windows

  • "Error while interacting with the scanner: the selected scanner was not found." Called brother and my MFC 7360N works very well with other programs to scan - only problem with Adobe Acrobat Pro 11.

    "Error while interacting with the scanner: the selected scanner was not found." Called brother and my MFC 7360N works very well with other programs to scan - only problem with Adobe Acrobat Pro 11.

    Hi davidd67669685,

    Please provide the exact point of the software & OS installed on your system. Also check if it is there any update available for the software after going through "help > check updates.

    Follow this thread to reset the Acrobat preferences:- How to reset preference settings in format Acrobat.

    You can check after connecting this scanner locally to the system if asked its connected on network & then look for the same thing.

    Please refer to this article:- of the troubleshooting tips for scanning questions when using Acrobat

    If the problem persists ask please check with another user account.

    Kind regards

    Christian

  • Lightroom CC: Develop module: I see only a blue box with a cross inside. If I select before / after, I can only see the picture before and not after after is displayed as a blue box with a cross inside. I can make adjustments, but I don't see them because

    Adobe Lightroom CC:

    Develop a module:

    Instead of my photos were corrected, I see only a blue box with a cross inside.

    If I select before / after, I can only see the picture before and not after (the corrections).

    After appears as a blue box with a cross inside.

    I can make adjustments, but I do not see them because the image after is not visible, it is a blue box with a cross inside.

    Thanks in advance for your help.

    Disable the option of processor graphics use in the performance of the LR preferences section.

  • There is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name

    Hello

    Doc Oracle says the following on the identifiers in the SELECT in PL/SQL clause: there is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name.

    If we assume that only valid column identifier are allowed in the SELECT clause.

    But I tried the following:

    DECLARE
    toto NUMBER := 10;
    tata NUMBER := 0;
    BEGIN
    SELECT toto INTO tata FROM employees WHERE employee_id = 101;
    DBMS_OUTPUT.PUT_LINE(tata);
    END;
    /
    

    And there is no error telling me that toto is not a column in the employees table and the result is the same as: toto: = aunt;

    Won't the doc or did I just miss something?

    Thanks for your response!

    Hello

    rep0ne wrote:

    Hello

    Doc Oracle says the following on the identifiers in the SELECT in PL/SQL clause: there is no possibility of ambiguity in the SELECT clause because any identifier in the SELECT clause must be a database column name.

    If we assume that only valid column identifier are allowed in the SELECT clause.

    Post a link to this Oracle doc.

    But I tried the following:

    1. DECLARE
    2. Toto NUMBER: = 10;
    3. Auntie NUMBER: = 0;
    4. BEGIN
    5. SELECT toto IN Auntie FROM Employees WHERE employee_id = 101;
    6. DBMS_OUTPUT. Put_line (Auntie);
    7. END;
    8. /

    And there is no error telling me that toto is not a column in the employees table and the result is the same as: toto: = aunt;

    ...

    You're right that toto is an identifier, but this isn't a column name.  (Of a subquery) column alias are not database of the names of columns either, nor are the names of the user-defined function.

    Also, there is a possibility for ambiguity even if all the names are the database column names.

    Won't the doc or did I just miss something?

    I can't say until I see the doc you're talking about.

    Oracle documentation is sometimes misleading and sometimes just plain wrong.  For each mistake outright example that I saw in the docs of Oracle, there might be 20 cases where the meaning is unclear or misleading and maybe 200 where I just read it wrong.

  • A subquery in the From Clause

    How can I model the RPD with the sub query that has the subquery in the from Clause.

    SELECT

    o948938. CONSOLIDATED_NAME,

    (SUM (o948992. YTD_COMPLETED)) / (SUM (TOTAL_OCC_AP)) AS C_1,.

    SUM (TOTAL_OCC_AP) AS TOTAL_OCC_AP,

    Of

    ORG_DIM o948938,

    TIME_MONTHLY_DIM o948963,

    INSPECTION_FACT o948992,

    (SELECT TDS_NUM,

    MONTH_ID,

    SUM (TOTAL_APTS) TOTAL_AP,

    OF SUMMARY_FACT

    TDS_NUM GROUP,

    MONTH_ID

    ) O949126

    WHERE (o949126. MONTH_ID = o948992. MONTH_ID (+)

    AND o949126. TDS_NUM = o948992. TDS_NUM (+)

    AND (o948938. TDS_NUM = o949126. TDS_NUM)

    AND (O948963. MONTH_ID = O949126. MONTH_ID))

    Group

    O948938. NEW_BOROUGH_GROUPING

    Hello

    You can do this via an opaque view.

    You can also do this by modeling the cumulative value as a calculation LOGIC in the group by aggregation "pinned" to a specific dimension hierarchy that reflects consolidation in the online posting.

    Hope this helps,

    Robert.

  • Decimal separator in the SELECT Clause

    Hello

    I have the following parameters of decimal number:

    SQL > select value
    2 from v$ nls_parameters
    3 where parameter = "NLS_NUMERIC_CHARACTERS;

    VALUE
    ----------------------------------------------------------------
    ,.

    If I show a decimal number, I get a comma as decimal separator
    SQL > select 10/100 double;

    10/100
    ----------
    1

    But if I use a decimal separator in the SELECT clause, I get:

    SQL > select 100 * 1.1 double;

    100 * 1 1
    ---------- ----------
    1 100

    It does not work. But the use of a period as the decimal separator works:

    SQL > select 1.1 * 100 double;

    1.1 * 100
    ----------
    110

    Maybe it's something that I never had to deal with before, but I thought that the number format applied to results of sql, as well as the numbers you have used sql clauses.

    Kind regards

    Nestor Boscan

    Hi, Nestor,

    user594312 wrote:
    ... I thought that the number format applied to results of sql, as well as the numbers you have used sql clauses.

    No.; it applies to the results and it can affect implicit conversions, but it does not apply to the SQL code.
    The period (or dot, '.') is the decimal separator in literals always digital. There is no way to change this.

    Think how confusing it would be if it applied to the SQL code. For example:

    WHERE   num_col  IN (1,2)
    

    We compare num_col values 1 or 2? He comes in, what happens if we wanted to do the opposite?

    If you really want to use the comma as the decimal separator, you may have to use strings, not numbers, and it could be much less effective.
    For example:

    SELECT  100 * TO_NUMBER ('1,1')    -- This assumes your NLS settings are correct
    FROM    dual;
    

    Of course, the effectiveness will not be a problem when you select 1 row of double.

  • INSERT the SEQ WITH the question of the Select clause

    Hello
    I have Insert statement that I want to use seq with the select clause, but does not please help in this...

    Insert in aaa (rowname, rowid, rowadd)
    aa_seq.nextval, empaddress, and Select empname from emp;
    Please, do not help to accommodate seq in the insert statement.
    Insert into aaa(rid,rowname,rowadd)
    select aa_seq.nextval, empname,empaddress from emp;
    

    Do not use as ROWID column name.

  • When I select print for a message preview mode, I get an error "the selected printer is not found." I can print the message, but I can't preview the output. I have

    I found that someone else has had this problem, but solution of Matt necessary use of the configuration editor. I followed the instructions, but by clicking on the Advanced tab, there was no Config Editor tab in order to execute the next step of the solution. BTW, I look in the console error log and see what: couldn't read the chrome manifest ' queue: / / / C:/Program % program % 20Thunderbird 20(x86) /Mozilla % 20Files / chrome.manifest'. The error itself is small box with Print Preview error as the label and The selected printer is not found as the contents of the box. Any help much appreciated.

    You look under Tools | Options | Advanced | General? In the main menu, which is the traditional one that spans the top of Thunderbird?

  • I accidentally created an email acct, how I remove to the newest one and not the former?

    Entally created an acct email, how do I remove to the newest one and not the former? And I get e just on the other.

    Play the 'e' (email?) to the old account first. You can drag and drop.

    To remove an account from Thunderbird:

    Tools | Account settings| < select the unwanted account > |

    Down at the bottom of the left pane, Account Actions , and then click remove account.

    Both accounts use POP? This could explain why new messages appear in the new account, but not the former.

    It might help to post your Thunderbird settings data: Help. Troubleshooting information. Clear the checkbox "include account names. Click on "Copy text to the Clipboard", then paste (ctrl + v) into your next post here.

Maybe you are looking for