SQL - ORA-00979: not a GROUP BY expression
Hi Expert,I received the error message: ORA-00979: not a GROUP BY expression at the bottom of the sql statement
Please advise - display total number of point of sale and the total amount of all items. Only display results when the total quantity is greater than 2.
SELECT o.Qty, sum(o.Qty*o.salesprice) AS TOTALDOLLARS, description and i.Itemcode
OF ORDERLINE o
INNER JOIN POINT I
ON o.itemcode = i.itemcode
GROUP BY i.Itemcode
After having o.qty > 2
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
Create table ORDERLINE
(
Qty number 4,
Salesprice Number (6.2),
OrderNo Number (3).
ItemCode Varchar2 (6).
Primary key (OrderNo, Itemcode)
Foreign Key (Itemcode) refers to POINT.
Foreign Key (OrderNo) made reference SALESORDER
Create table POINT
(
ItemCode Varchar2 (6).
Description Varchar2 (50).
Retailprice Number (6.2),
Number of weight (4.1),
Purchaseprice Number (6.2),
Category Varchar2 (20).
Primary Key (Itemcode)
);
Hi 845720,
Based on the sql code, the sum must be grouped itemcodewise, descriptionwise, qtywise.
This means that you have all these in a group by clause too with sum().
eg : group by i.Itemcode, i.Description, o.Qty
Is this wise sum qty is logical? I do not know...
It will be useful,
CKLP
Published by: CKLP April 14, 2011 22:10
Tags: Database
Similar Questions
-
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
-
ORA-00979: not a GROUP BY expression
Hello
And if you want to include aggregate functions, you must make sure of all the other columns are included in the group by clause...
SELECT THE CAG. SystemId,
CAG. BankId,
CR. ClearingNumber,
CAG. AgreementId,
CAs.timestampchanged AS ApprovedLGDDate,
LGD. ApprovedLGDValue,
CASE. ModelId,
CASE. ModelVersion,
CAG. CaseId,
CASE. Creator,
BOX WHEN CAG. SystemId = 'ASK' THEN CAG. SystemidProduct
ANOTHER NULL
END as SystemidProd,
BOX WHEN CAG. SystemId = 'REQUEST' AND CAG.agreementid LIKE ' %: % ' THEN
To_char (TO_NUMBER (SUBSTR (CAG.agreementid, INSTR (CAG.agreementid, ' :') + 1), "xxxxxxxxxxxxxxx")))
WHEN CAG. SystemId = 'REQUEST' AND CAG.agreementid NOT LIKE ' %: % ' THEN
CAG.agreementid
ANOTHER NULL
END as AgreementidUNP,
case. DecisionDate
OF CAG CustomerAgreement
JOIN CreditLGD LGD ON (CAG. SystemId = LGD. SystemId
AND CAG. BankId = LGD. BankId
AND CAG. AgreementId = LGD. AgreementId
AND CAG. AgreementSubId = LGD. AgreementSubId
AND CAG. CaseId = LGD. CaseId
)
Credit to JOIN CR ON (CAG. SystemId = CR. SystemId
AND CAG. BankId = CR. BankId
AND CAG. AgreementId = CR. AgreementId
AND CAG. AgreementSubId = CR. AgreementSubId
AND CAG. CaseId = CR. CaseId
)
NO. CASE CASE OF JOIN ON (CAG. BankId = CASE. BankId
AND CAG. CaseId = CASE. CaseId
AND THE AC. State = 'approved '.
)
JOIN CU customer ON (CU.bankid = CAS.bankid
AND CU.latestapprovedcaseid = CAS.caseid
AND CU.customerid = CR.customerid
)
WHERE CAG. SYSTEMID IN ("ACC", "APL", "GOF", "GRK", "HPD", "KRF", "LIM", "PRO", "SPI", "SPS", "ASK")
CAG group. SystemId
CAG. BankId
CR. ClearingNumber
CAG. AgreementId
cas.timestampchanged
LGD. ApprovedLGDValue
CASE. ModelId
CASE. ModelVersion
CAG. CaseId
CASE. Creator
CASE WHEN CAG. SystemId = 'ASK' THEN CAG. SystemidProduct
ANOTHER NULL
END
CASE WHEN CAG. SystemId = 'REQUEST' AND CAG.agreementid LIKE ' %: % ' THEN
To_char (TO_NUMBER (SUBSTR (CAG.agreementid, INSTR (CAG.agreementid, ' :') + 1), "xxxxxxxxxxxxxxx")))
WHEN CAG. SystemId = 'REQUEST' AND CAG.agreementid NOT LIKE ' %: % ' THEN
CAG.agreementid
ANOTHER NULL
END
cas.decisiondate -
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_codeQuite a few differences...
-
SQL error: ORA-00979: not a GROUP BY
Hi team,
I am trying to execute the query
SELECT DISTINCT comp.company_name |' -' || COMP.contract_number AS 'company_name '.
, UPPER (bh.first_name) AS 'budget_holder '.
, INITCAP (sup.first_name) |' -' || SUP. Surname AS 'supervisor '.
, INITCAP (emp.status) AS "Department".
, INITCAP (emp.first_name |) » '|| EMP. Surname) AS "employee."
r.employee_id
, emp.paaf_number AS 'paaf_num '.
, emp.employee_payroll_number AS 'payroll_num '.
, emp.discipline AS 'discipline '.
, NVL (SUM (tg.week_day1), 0) AS "day 1".
, NVL (SUM (tg.week_day2), 0) AS "day 2".
, NVL (SUM (tg.week_day3), 0) AS day '3 '.
, NVL (SUM (tg.week_day4), 0) AS "day4.
, NVL (SUM (tg.week_day5), 0) AS "day5".
, NVL (SUM (tg.week_day6), 0) AS "day6.
, NVL (SUM (tg.week_day7), 0) AS "day 7".
r.valid_from
r.valid_to
Tw_roster_data r
JOIN tw_employee emp
ON emp.employee_id = r.employee_id
JOIN tg tw_timesheet_stage
ON tg.employee_id = r.employee_id
AND tg.week_commencing = r.valid_from
JOIN the tw_contracting_company comp
ON comp.contracting_company_id = r.contracting_company_id
JOIN tw_supervisor sup
ON sup.supervisor_id = tg.supervisor_id
JOIN tw_budget_holder bh
ON bh.budget_holder_id = sup.budget_holder_id
WHERE r.contracting_company_id = 101
AND r.VALID_FROM = January 31, 2015.
AND r.VALID_TO = February 6, 2015"
Group of r.employee_id, comp.company_name, bh.first_name,
EMP.paaf_number, emp.employee_payroll_number, emp.discipline,
r.valid_from, r.valid_to;
But still the error below
Error in the command line: 1 column: 17
Error report-
SQL error: ORA-00979: not a GROUP BY expression
00979 00000 - "not a GROUP BY expression"
Can help.
Hello
When to use analytical function oracle other columns used based on the analysis, must be included in the GROUP BY Clause
SELECT expression1, expression2, ... expression_n, aggregate_function (expression) FROM tables WHERE conditions GROUP BY expression1, expression2, ... expression_n;
SQL 101: Seen are medium and other aggregate data
SELECT DISTINCT comp.company_name || ' - ' || comp.contract_number AS "company_name", UPPER (bh.first_name) AS "budget_holder", INITCAP (sup.first_name) || ' - ' || sup.surname AS "supervisor", INITCAP (emp.status) AS "department", INITCAP (emp.first_name || ' ' || emp.surname) AS "employee", r.employee_id, emp.paaf_number AS "paaf_num", emp.employee_payroll_number AS "payroll_num", emp.discipline AS "discipline", NVL (SUM (tg.week_day1), 0) AS "day1", NVL (SUM (tg.week_day2), 0) AS "day2", NVL (SUM (tg.week_day3), 0) AS "day3", NVL (SUM (tg.week_day4), 0) AS "day4", NVL (SUM (tg.week_day5), 0) AS "day5", NVL (SUM (tg.week_day6), 0) AS "day6", NVL (SUM (tg.week_day7), 0) AS "day7", r.valid_from, r.valid_to FROM tw_roster_data r JOIN tw_employee emp ON emp.employee_id = r.employee_id JOIN tw_timesheet_stage tg ON tg.employee_id = r.employee_id AND tg.week_commencing = r.valid_from JOIN tw_contracting_company comp ON comp.contracting_company_id = r.contracting_company_id JOIN tw_supervisor sup ON sup.supervisor_id = tg.supervisor_id JOIN tw_budget_holder bh ON bh.budget_holder_id = sup.budget_holder_id WHERE r.contracting_company_id = 101 AND r.VALID_FROM = '31-JAN-2015' AND r.VALID_TO = '06-FEB-2015' GROUP BY comp.contract_number ,comp.company_name ,bh.first_name ,sup.first_name ,sup.surname , emp.status ,emp.first_name ,emp.surname r.employee_id, emp.paaf_number, emp.employee_payroll_number, emp.discipline, r.valid_from, r.valid_to;
-
ORA-00979: not a GROUP-BY-error expression
Hello
We moved just our project mysql database to oracle 10 database. The migration was made manually, without the use of tools. We had to change many queries to oracle suit. The following query when it is run on mysql works perfectly well. But when I run it in oracle, it gives the error mentioned in the subject.
-----
Select distinct d.managedserverid, s.hostname, m.port, a.applicationname, max (d.versionid) of table1, table2 m, s table3, table 4 d, where d.applicationid = '1' and d.Active = 'True' and d.managedserverid = m.managedserverid and m.serverid = s.serverid and d.applicationid = a.applicationid group by d.managedserverid;
-----
Any help would be appreciated.
Thank you
SAPPHello
Welcome to the forum.
When you use the aggregate functions such as min, max, sum, etc. you have to group the columns not aggregated in the select query.
Try this.
select d.managedserverid, s.hostname, m.port, a.applicationname, max(d.versionid) from table1 d, table2 m, table3 s, table4 a where d.applicationid = '1' and d.Active = 'True' and d.managedserverid = m.managedserverid and m.serverid = s.serverid and d.applicationid = a.applicationid group by d.managedserverid, s.hostname, m.port, a.applicationname
HTH,
Prazy -
error: not a GROUP BY expression
Hello world
Looks like I need some help here... :) don't know what that means, but im getting this message
00979 00000 - "not a GROUP BY expression"
* Cause:
* Action:
Error on line: column 137: 36
It's the function:
function get_path (materialID in number, materialTypeID number, inTopFolderID number default null, inMaterialFolderID in the number default null, webMode in default number 1 in)
return varchar2;
and im using it on my query
, (select material_util.get_path (m.material_id, 8, 1021695, min (mf.)) (IP_MATERIALFOLDERID), 1).
material m, materialfolder mf
where mf.nfx_link = m.MATERIAL_ID
and t.template_id = m.template_id) as path
It seems that min (mf. IP_MATERIALFOLDERID) is having some problems here... don't know why...
Let me know guys...
Thank you...
JRead below for informative post from Frank Kulash on ABC in the group by clause
{message: id = 9969583} -
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
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".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;
Can someone suggest a way for a new concert the query so that I can add po_number to my education by clause.
KrisYou 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; -
PL/SQL: ORA-00947: not enough values error message
Hi all I get Error (25.63): PL/SQL: ORA-00947: not enough error message values when executing after the insert statement. I am new to Oracle SPs, if someone could help me solve the problem.
Insert in estimate (ID, mValue) values ('select (where pm.ID is null then 10))
of other pm.ID
End ID), m1.mID, (case when mValue < 1 and m1.mID in (1.7))
then mValue * 100
of another mValue
mValue end) of
Scott. Left outer join METRICS m1
Scott. (PROJECTMETRIC h m1.mID = pm.ID and pm.ID = 10)');The syntax to insert rows into a table of a subquery is as follows:
insert into table (col1, col2, ...) select ... , ..., .... from ..., .... where .... /
-
I have the following table AR_Complex
Country_code Country Complex_Amt Child_Amt CC_1 CC 5000 1000 CC_1 CC 1000 CC_1 CC 2000 CC_1 CC 1000 US_2 WE 3000 1000 US_2 WE 500 US_2 WE 200 US_2 WE 100 I wrote the following query
Select * from (select Country_code, sum (Complex_Amt), sum (Child_Amt), (sum (Complex_Amt) - sum (Child_Amt)) as a Diff of AR_Complex
Country_code group)
where Diff > 1
which works very well.
How can I get the Country column in the query because when I adds the Country column it does not appear a group by EXPRESSION.
I think you want:
Select * from (select Country_code, country, sum (Complex_Amt), sum (Child_Amt), (sum (Complex_Amt) - sum (Child_Amt)) as a Diff of AR_Complex
Country_code group, country)
where Diff > 1
-
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:
-
Classic report command SQL ORA-00933 not properly completed when you enable sorting
Hello
Oracle 11g r2, APEX 4.1.1.00.23.
I have a few reports of type SQL Query (PL/SQL, returning the SQL query function body), so the source is as follows:
Without no sort option, the report is made successfully.begin return points_ui.get_points_query(:P0_FILTER_TYPE); end;
But I got the following error during a test to enable the sorting option for a column:
I read about this error on the Oracle forums, and I saw it was a bug in an older version, but I thought it was fixed in 4.0.2...ORA-00933: SQL command not properly ended
Any help would be appreciated.
Thank you.
Yann.The Order By clause and the column sort is kind of mutually exclusive.
If your SQL in the report area has an Order By inside and you apply the sort order on the columns in the report attributes tab, then errors occur during execution.Concerning
-
Order SQL ORA-00933 not correctly completed, UNION ALL
I apologize if it's really simple, but it made me turn round...
I inherited the spaghetti code to fix and revise (550 line sql request sent from VBA). I'm putting it in pieces in the form of views. In the following code, I'm calling two subqueries, which I stored in the form of views (Credit_Report_Exposure_P_Sub_A and Credit_Report_Exposure_P_Sub_B). I have create a UNION of them, and it works fine - until I add a WHERE clause. So:
---------------------------------------------------------------------------------
SELECT
PROFILENAME,
months,
sum
Of
Credit_Report_Exposure_P_Sub_A
UNION ALL
(SELECT
ccp_profile_name PROFILENAME,
VWMONTH month,
SUM SUM (PSJ_TOTAL_AMOUNT)
Of
Credit_Report_Exposure_P_Sub_B
GROUP by
VWMONTH,
ccp_profile_name)
------------------------------------------------------------------------------------------
It works very well, to select the same 3 columns in each subquery (ignoring for a moment the wrong choice of alias 'months' and 'sum').
But when I add the following WHERE clause:
------------------------------------------------------------------------------------------
WHERE
month = ' 2008-09'
------------------------------------------------------------------------------------------
I get the error in the subject line - which is not properly completed.
But: if I comment on each half of the UNION, so the WHERE clause works very well.
Am I missing something obvious? I tried wrapping the whole of the UNION more in parentheses, and the first clause of the UNION as well, but that only creates more errors on supposed lack of right parens.
Thanks for any help.Hello
Whenever you have a problem with a query, view query. It is unclear where exactly you added the WHERE clause.
You don't need parentheses around the second part of the UNION all.
Half of the effect of the WHERE clause of the will UNION ALL? If both, you must add two times, or do the UNION ALL in a subquery and add the WHERE clause to the query of super.
-
Error ORA-00979 when you run the SQL in Oracle 11.2.0.3
Hi Oracle Experts,
I am trying to execute a SQL statement which consist of 2-3 levels of inline queries. Part of this SQL statement is as below:
When I run the level the lowest and second lowest level inline queries statements, which consists of a select field of data and functions, there is no error and capable of generating the result.SELECT "SAMPLE_RESULT"."PROPERTYID", "SAMPLE_RESULT"."QUALIFIER", ROUND(AVG(SAMPLE_RESULT.RESULT),2) avg_result, AVG(DECODE(SAMPLE.QUALITYSTATUS, 'P', 1,'F', 5)) qltystatus, TO_CHAR("SAMPLE"."SAMPLEDT",'dd-Mon-yyyy') sampledt, TO_CHAR("SAMPLE"."SAMPLEDT",'rrrr-mm-dd') sortdate STD.stdev, getCL.cl FROM ( SELECT ROUND(stddev(INS.avg_result),2) stdev FROM ( SELECT "SAMPLE_RESULT"."PROPERTYID", "SAMPLE_RESULT"."QUALIFIER", ROUND(AVG(SAMPLE_RESULT.RESULT),2) avg_result, AVG(DECODE(SAMPLE.QUALITYSTATUS, 'P', 1,'F', 5)) qltystatus, TO_CHAR("SAMPLE"."SAMPLEDT",'dd-Mon-yyyy') sampledt FROM "SAMPLE", "SAMPLE_RESULT", "ACTIVITY" WHERE ( "SAMPLE"."SAMPLEID" = "SAMPLE_RESULT"."SAMPLEID" ) AND ( "SAMPLE_RESULT"."TESTINSTANCE" = fn_max_instance ( sample.sampleid, sample_result.testid, sample_result.propertyid ) ) AND ( "SAMPLE"."ACTIVITYID" = "ACTIVITY"."ACTIVITYID" ) AND ( ACTIVITY.VARIANTID IN ('Sales Gas','Contaminants End') ) AND ( ACTIVITY.LOCATIONID = 'S-5003C' ) AND ( SAMPLE.EVENTID <> 'AD-HOC' ) AND ( "SAMPLE"."SAMPLESTATUS" = 'L' ) AND ( TO_DATE(TO_CHAR(SAMPLE.SAMPLEDT,'dd-mon-yyyy')) BETWEEN TO_DATE (TO_CHAR(:StartDate,'dd-Mon-RRRR')) AND TO_DATE(TO_CHAR( :StartDate,'dd-Mon-RRRR')) + 6 ) AND ( SAMPLE_RESULT.PROPERTYID = 'GCV' ) GROUP BY SAMPLE_RESULT.PROPERTYID, SAMPLE_RESULT.QUALIFIER, TO_CHAR("SAMPLE"."SAMPLEDT",'dd-Mon-yyyy') ) INS ) STD, ( SELECT ROUND(AVG(INS.avg_result),2) cl FROM ( SELECT "SAMPLE_RESULT"."PROPERTYID", "SAMPLE_RESULT"."QUALIFIER", ROUND(AVG(SAMPLE_RESULT.RESULT),2) avg_result, AVG(DECODE(SAMPLE.QUALITYSTATUS, 'P', 1,'F', 5)) qltystatus, TO_CHAR("SAMPLE"."SAMPLEDT",'dd-Mon-yyyy') sampledt FROM "SAMPLE", "SAMPLE_RESULT", "ACTIVITY" WHERE ( "SAMPLE"."SAMPLEID" = "SAMPLE_RESULT"."SAMPLEID" ) AND ( "SAMPLE_RESULT"."TESTINSTANCE" = fn_max_instance ( sample.sampleid, sample_result.testid, sample_result.propertyid ) ) AND ( "SAMPLE"."ACTIVITYID" = "ACTIVITY"."ACTIVITYID" ) AND ( ACTIVITY.VARIANTID IN ('Sales Gas','Contaminants End') ) AND ( ACTIVITY.LOCATIONID = 'S-5003C' ) AND ( SAMPLE.EVENTID <> 'AD-HOC' ) AND ( "SAMPLE"."SAMPLESTATUS" = 'L' ) AND ( TO_DATE(TO_CHAR(SAMPLE.SAMPLEDT,'dd-mon-yyyy')) BETWEEN TO_DATE (TO_CHAR(:StartDate,'dd-Mon-RRRR')) AND TO_DATE(TO_CHAR( :StartDate,'dd-Mon-RRRR')) + 6 ) AND ( SAMPLE_RESULT.PROPERTYID = 'GCV' ) GROUP BY SAMPLE_RESULT.PROPERTYID, SAMPLE_RESULT.QUALIFIER, TO_CHAR("SAMPLE"."SAMPLEDT",'dd-Mon-yyyy') ) INS ) getCL, "SAMPLE", "SAMPLE_RESULT", "ACTIVITY" WHERE ( "SAMPLE"."SAMPLEID" = "SAMPLE_RESULT"."SAMPLEID" ) AND ( "SAMPLE_RESULT"."TESTINSTANCE" = fn_max_instance (sample.sampleid, sample_result.testid, sample_result.propertyid) ) AND ( "SAMPLE"."ACTIVITYID" = "ACTIVITY"."ACTIVITYID" ) AND ( ACTIVITY.VARIANTID IN ('Sales Gas','Contaminants End') ) AND ( ACTIVITY.LOCATIONID = 'S-5003C' ) AND ( SAMPLE_RESULT.PROPERTYID IN ('GCV','SG','T. Sulphur','Dew Point', 'HC Dew Pts') ) AND ( TO_DATE(TO_CHAR(SAMPLE.SAMPLEDT,'dd-mon-yyyy')) BETWEEN TO_DATE(TO_CHAR (:StartDate,'dd-Mon-RRRR')) AND TO_DATE(TO_CHAR(:StartDate, 'dd-Mon-RRRR')) + 6 ) GROUP BY "SAMPLE_RESULT"."PROPERTYID", "SAMPLE_RESULT"."QUALIFIER", TO_CHAR("SAMPLE"."SAMPLEDT",'dd-Mon-yyyy'), TO_CHAR("SAMPLE"."SAMPLEDT",'rrrr-mm-dd'), STD.stdev, getCL.cl )
But when I run the statement which refer to the alias of queries inline (STD, getCL), it prompted an error ORA-00979 not a group by expression. This happened only Oracle 11.2.0.3. If I run the statement in another version of Oracle (11 GR 1 material and below), I am able to generate the result.
Please advice how can I fix this problem.
Published by: xysOra on 29 April 2013 19:37It seems that this should be the "SAMPLE" TO_CHAR conversions "" SAMPLEDT ".
You seem to be willing to cut the time part of SAMPLEDT. The best way to do so is TRUNC (SAMPLEDT).
In each of the groups of clauses, replace TO_CHAR ('SAMPLE'. ("' SAMPLEDT ', 'dd-Mon-yyyy') with TRUNC ('SAMPLE'. (' "SAMPLEDT") and completely remove the TO_CHAR ('SAMPLE'. ("' SAMPLEDT ',"dd-mm-rrrr") in the last group of.
Replace in selection lists, TO_CHAR ('SAMPLE'. ("' SAMPLEDT ', 'dd-Mon-yyyy') with TO_CHAR (TRUNC ('SAMPLE'. ((' ' SAMPLEDT '), 'dd-Mon-yyyy') and replace TO_CHAR ("SAMPLE". "SAMPLEDT", "dd-mm-rrrr") with TO_CHAR (TRUNC ("SAMPLE" ".")) " "" "SAMPLEDT"), "dd-mm-rrrr").
These changes can take you the ORA-00979 not one group by expression.
Also the date manipulation is wrong — you do implicit conversions to date using default formats, when what you seem to want is to truncate the time part. Instead of
TO_DATE(TO_CHAR(SAMPLE.SAMPLEDT,'dd-mon-yyyy')) BETWEEN TO_DATE(TO_CHAR (:StartDate,'dd-Mon-RRRR')) AND TO_DATE(TO_CHAR(:StartDate, 'dd-Mon-RRRR')) + 6
use
TRUNC(SAMPLE.SAMPLEDT) BETWEEN TRUNC(:StartDate) AND TRUNC(:StartDate) + 6
I hope this helps.
David -
ORA-00979 in one but not the other. Why?
Oracle Database 11 g Enterprise Edition Release 11.1.0.6.0 - 64 bit Production
SELECT the 'X' WHEN A.Dummy 42 THEN END OF double, (SELECT Dummy FROM Dual) a GROUP OF Dual.Dummy;
SELECT the 'X' WHEN A.Dummy 42 THEN END OF double, (SELECT ' X' FROM Dual Dummy) a GROUP OF Dual.Dummy;
First an error: ORA-00979: not a GROUP BY expression
Other works.
Why?Hello
This seems to be a transformation/display fusion issue queries. You can replicate the behavior in the second query using the no_merge hint...
SELECT CASE 'X' WHEN A.Dummy THEN 42 END FROM Dual, (SELECT /*+ no_merge */ 'X' Dummy FROM Dual) A GROUP BY Dual.Dummy; SELECT CASE 'X' WHEN A.Dummy THEN 42 END FROM Dual, (SELECT 'X' Dummy FROM Dual) A GROUP BY Dual.Dummy; XXXX> SELECT 2 CASE 'X' WHEN A.Dummy THEN 42 3 END 4 FROM 5 Dual, 6 (SELECT /*+ no_merge */ 'X' Dummy FROM Dual) A 7 GROUP BY 8 Dual.Dummy; CASE 'X' WHEN A.Dummy THEN 42 * ERROR at line 2: ORA-00979: not a GROUP BY expression Elapsed: 00:00:00.03 XXXX> XXXX> SELECT 2 CASE 'X' WHEN A.Dummy THEN 42 3 END 4 FROM 5 Dual, 6 (SELECT 'X' Dummy FROM Dual) A 7 GROUP BY 8 Dual.Dummy; CASE'X'WHENA.DUMMYTHEN42END --------------------------- 42 1 row selected.
If you run a trace 10053, you should be able to see the specific cause
HTH
David
BANNER ---------------------------------------------------------------- Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi PL/SQL Release 10.2.0.4.0 - Production CORE 10.2.0.4.0 Production TNS for Solaris: Version 10.2.0.4.0 - Production NLSRTL Version 10.2.0.4.0 - Production 5 rows selected.
Published by: Bravid on February 28, 2012 17:21
Maybe you are looking for
-
Can not find podcasts in iTunes store
I can't find my podcasts in the iTunes store. On my other computer laptop is fine, but on my new computer the provider (such as NPR) appears, but several podcasts don't, like the money in the world. Why are they hiding? And how to find them?
-
MacBook Pro 15 "retina, end of 2013, black screen of
I had been on a trip, using the mac to the airport before our last flight, closed the lid (standby mode). Placed in the bag next to my Tablet back (usually had a little space between them). When I got home I tried to reactivate and at first thought h
-
Recovery for Tecra A3-s611 disk is no longer supplied by Toshiba
I wanted to format the HDD on a Tecra A3-s611 since she had a downloader Trojan horse could have malware 0 - day. I knew that the recovery disc has been lost, but I thought that a retail Windows disc would work with the license key of Toshiba. It did
-
I used the dropbox community Possin qbittorrentr6_3.3.0_armel.deb and since then I can't access the web interface. The default admin and adminadmin password do not work nor has my original password from the old version. I tried to remove and reinstal
-
Manual integration of MS2010 and VS2010 does not
Hello This is a newbie question, but I have some difficulty to get Visual Studio 2010 to integrate with Measurement Studio 2010. I tried to follow the instructions to manually integrate MS vs on the following page: http://digital.NI.com/public.nsf/al