Help with inline view query
Hi
I have written a query that is supposed to return the following result.
LOCATION YOUNGEST ELDEST
york Name Name
Luton Name NameI am having trouble with the INNER JOIN of the outer query. I cannot seem to match up both the YOUNGEST and ELDEST COLUMNS, only one of them. Does anyone know how I match it up to produce the appropriate result
SELECT
res.ldes,
a.first_name||' '||a.last_name YOUNGEST,
a.first_name||' '||a.last_name ELDEST
FROM
SELECT
l.description ldes,
MAX(a.birth_date) maxbd,
MIN(a.birth_date) minbd
FROM
locations l
INNER JOIN
agents a
ON
l.location_id=a.location_id
GROUP BY
l.description
) res
INNER JOIN
agents a
ON
a.birth_date = res.maxbd --PROBLEM IS HERE need to match up a.birth_date with res.minbd also but cannot get it
ORDER BY
res.ldesThanks for any response
metzquar gave your answer.
try
with locations as(select 10 location_id,'ABC' description from dual union all
select 20,'XYZ' from dual union all
select 30,'RPF' from dual),
agents as(select 10 location_id,'IM' first_name,'ELDEST' last_name,to_date('08/08/1988','mm/dd/yyyy') birth_date from dual union all
select 20,'IM','ELDEST', to_date('08/08/1988','mm/dd/yyyy') from dual union all
select 30,'IM','ELDEST', to_date('08/08/1988','mm/dd/yyyy') from dual union all
select 10,'IM','MIDAGE', to_date('07/07/1977','mm/dd/yyyy') from dual union all
select 20,'IM','MIDAGE', to_date('07/07/1977','mm/dd/yyyy') from dual union all
select 30,'IM','MIDAGE', to_date('07/07/1977','mm/dd/yyyy') from dual union all
select 10,'IM','YOUNGEST', to_date('06/06/1966','mm/dd/yyyy') from dual union all
select 20,'IM','YOUNGEST', to_date('06/06/1966','mm/dd/yyyy') from dual union all
select 30,'IM','YOUNGEST', to_date('06/06/1966','mm/dd/yyyy') from dual)
SELECT l.description ldes,
MIN(a.first_name || ' ' || a.last_name)KEEP (DENSE_RANK FIRST ORDER BY a.birth_date) AS youngest,
MIN(a.first_name || ' ' || a.last_name)KEEP (DENSE_RANK LAST ORDER BY a.birth_date) AS eldest
FROM locations l INNER JOIN agents a ON l.location_id = a.location_id
GROUP BY l.description
ORDER BY 1;
O/P:-
LDES YOUNGEST ELDEST
ABC IM YOUNGEST IM ELDEST
RPF IM YOUNGEST IM ELDEST
XYZ IM YOUNGEST IM ELDEST
Similar Messages
-
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,
NickIt 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. -
Need some help with the Select query.
Need some help with the Select query.
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
select single vkorg abgru from ZADS into it_rej.
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
This is causing performance issue. They are asking me to include the where condition for this select query.
What should be my select query here?
Please suggest....
Any suggestion will be apprecaiated!
Regards,
DeveloperHello Everybody!
Thank you for all your response!
I had changes this work area into Internal table and changed the select query. PLease let me know if this causes any performance issues?
I had created a Z table with the following fields :
ZADS :
MANDT
VKORG
ABGRU.
I had written a select query as below :
I had removed the select single and insted of using the Structure it_rej, I had changed it into Internal table
select vkorg abgru from ZADS into it_rej.
Earlier :
IT_REJ is a Work area:
DATA : BEGIN OF IT_REJ,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
Now :
DATA : BEGIN OF IT_REJ occurs 0,
VKORG TYPE VBAK-VKORG,
ABGRU TYPE VBAP-ABGRU,
END OF IT_REJ.
I guess this will fix the issue correct?
PLease suggest!
Regards,
Developer. -
Help with an SQL Query on the Logger
We are running UCCE 8.5(3) and need help with an SQL query. When I run the below I would also like to see skill group information(name preferably)? Any help would be greatly appreciated!
select * from dbo.t_Termination_Call_Detail where DateTime between '10-11-2012 00:00:00:00' and
'10-11-2012 23:59:59:59'David, thanks for replying. Unfortunitly I don't know enough about SQL to put that into a query and have it return data. Would you be able to give an example on what the query would look like?
-
Tuning query with inline views
Hi!
I have a performance problem with the following query. I try to combine v1 and v2 into one inline view but because of the recursive design of the tables workflow and workflow_node it didn't work.
Does anybody has an idea for tuning this query?
SELECT distinct v1.u_protocol_id
FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
FROM workflow_node,workflow,U_protocol
WHERE workflow.workflow_id=workflow_node.workflow_id
AND u_protocol.u_protocol_id = workflow_node.parameter_2
AND workflow_node.workflow_node_type_id=17
AND workflow.workflow_node_type_id=42
) v1,
( SELECT workflow_node.workflow_id,test_template.test_template_id
FROM workflow_node,test_template
WHERE test_template.test_template_id = workflow_node.template
AND workflow_node.order_number = 1
AND workflow_node.workflow_node_type_id=42
) v2,
( SELECT aliquot.aliquot_id,test_template.test_template_id
FROM aliquot,test,test_template
WHERE aliquot.aliquot_id = test.aliquot_id
AND test.test_template_id = test_template.test_template_id
) v3
WHERE v1.workflow_id = v2.workflow_id
AND v2.test_template_id= v3.test_template_idI have found a script (utlxplan.sql) for creating the plan_table so here it is
SQL> @c:\utlxplan.sql;
Table created.
SQL> EXPLAIN PLAN FOR SELECT distinct v1.u_protocol_id
2 FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
3 FROM lims_sys.workflow_node,lims_sys.workflow,lims_sys.U_protocol
4 WHERE workflow.workflow_id=workflow_node.workflow_id
5 AND u_protocol.u_protocol_id = workflow_node.parameter_2
6 AND workflow_node.workflow_node_type_id=17
7 AND workflow.workflow_node_type_id=42
8 ) v1,
9 ( SELECT workflow_node.workflow_id,test_template.test_template_id
10 FROM lims_sys.aliquot,lims_sys.test,lims_sys.workflow_node,lims_sys.test_template
11 WHERE aliquot.aliquot_id = test.aliquot_id
12 AND test.test_template_id = test_template.test_template_id
13 AND test_template.test_template_id = workflow_node.template
14 ) v2
15 WHERE v1.workflow_id = v2.workflow_id
16 /
Explained.
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id | Operation | Name |
Rows | Bytes | Cost |
| 0 | SELECT STATEMENT | |
PLAN_TABLE_OUTPUT
| | |
| 1 | SORT UNIQUE | |
| | |
| 2 | FILTER | |
| | |
| 3 | NESTED LOOPS | |
| | |
PLAN_TABLE_OUTPUT
| 4 | NESTED LOOPS | |
| | |
| 5 | NESTED LOOPS | |
| | |
| 6 | NESTED LOOPS | |
| | |
| 7 | NESTED LOOPS | |
| | |
PLAN_TABLE_OUTPUT
| 8 | NESTED LOOPS | |
| | |
| 9 | TABLE ACCESS BY INDEX ROWID| WORKFLOW |
| | |
|* 10 | INDEX RANGE SCAN | FK_WORKFLOW_WORKFLOW_NODE_TYPE |
| | |
| 11 | TABLE ACCESS BY INDEX ROWID| WORKFLOW_NODE |
PLAN_TABLE_OUTPUT
| | |
| 12 | AND-EQUAL | |
| | |
|* 13 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_WORKFLOW |
| | |
|* 14 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_NODE_TYPE |
| | |
PLAN_TABLE_OUTPUT
| 15 | TABLE ACCESS BY INDEX ROWID | U_PROTOCOL |
| | |
|* 16 | INDEX UNIQUE SCAN | PK_U_PROTOCOL |
| | |
| 17 | TABLE ACCESS BY INDEX ROWID | WORKFLOW_NODE |
| | |
|* 18 | INDEX RANGE SCAN | FK_WORKFLOW_NODE_WORKFLOW |
| | |
PLAN_TABLE_OUTPUT
| 19 | TABLE ACCESS BY INDEX ROWID | TEST_TEMPLATE |
| | |
|* 20 | INDEX UNIQUE SCAN | PK_TEST_TEMPLATE |
| | |
| 21 | TABLE ACCESS BY INDEX ROWID | TEST |
| | |
|* 22 | INDEX RANGE SCAN | FK_TEST_TEST_TEMPLATE |
PLAN_TABLE_OUTPUT
| | |
| 23 | TABLE ACCESS BY INDEX ROWID | ALIQUOT |
| | |
|* 24 | INDEX UNIQUE SCAN | PK_ALIQUOT |
| | |
| 25 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
PLAN_TABLE_OUTPUT
| 26 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 27 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 28 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
| 29 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP |
| | |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
10 - access("SYS_ALIAS_5"."WORKFLOW_NODE_TYPE_ID"=42)
13 - access("SYS_ALIAS_5"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
14 - access("WORKFLOW_NODE"."WORKFLOW_NODE_TYPE_ID"=17)
PLAN_TABLE_OUTPUT
16 - access("SYS_ALIAS_4"."U_PROTOCOL_ID"=TO_NUMBER("WORKFLOW_NODE"."PARAMETER
_2"))
18 - access("WORKFLOW_NODE"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
20 - access("SYS_ALIAS_1"."TEST_TEMPLATE_ID"="WORKFLOW_NODE"."TEMPLATE")
22 - access("SYS_ALIAS_2"."TEST_TEMPLATE_ID"="SYS_ALIAS_1"."TEST_TEMPLATE_ID")
24 - access("SYS_ALIAS_3"."ALIQUOT_ID"="SYS_ALIAS_2"."ALIQUOT_ID")
Note: rule based optimization -
Issue with Inline View Criteria
Hi,
I have a VO created on two tables that are joined by a 1:1 association(say Opportunity and Revenue). The query is specified in Expert mode because I need some aggregations performed using analytic functions. Data security predicates are applied on top of this query using a dummy View Criteria. My requirement now is that I need to filter these results using another VC. The issue is that both the tables have attributes with the same name(say Cust ID) and I need to filter based on this using an inline View Criteria. I have done the same declaratively. However, I get an error on hitting the page saying the columns have been ambiguously defined.
On digging through the log, I discovered the test Query fails to prefix the alias before the attribute. So what I get is something similar to this
select (o.id, r.amt, sum(), count(), avg(), o.custId) from opty o, revn r where (o.id in DATA SECURITY PREDICATE) and (custId = :bindCustId)
Is there a way to ensure that the custId can be changed to o.custId???
Note - The View Criteria was created on an attribute from opty table that was exposed i.e in this case, o.custId. Although the query builder shows it correctly while creating the VC declaratively, the issue persists as seen from the logs.
Thanks,
ManojHi experts...
Any pointers to this issue???
Please help!
Regards,
Debolina -
Improve performance of an inline view query
All,
I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
ex:
SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
but this design was rejected, because it seems to have a great impact on performance due to inline view.
Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
please help to find a alternative solution which helps to get the expected result set and same time without loosing performance.Hi,
The sql you gave us is not valid. There is no "col_b" in your inline view, there is no "where" before "rownum<10", and the inline view returns only one row.
Try to produce a reproducible scenario with scott.emp and scott.dept generated by $ORACLE_HOME/rdbms/admin/utlsampl.sql
Regards
Laurent -
Hi,
I have written the following query:
select customer.cust_id as "Customer ID"
,customer.cust_area_code as "Customer Area Code"
,customer.cust_number as "Customer Number"
,sum(calls.elapsed_minutes) as "Total Call Length (Mins)"
,sum(calls.elapsed_minutes*calls.rate) as "Total Cost Of Calls £"
from
(select cust_id
,floor((end_date_time-start_date_time)*1440) as elapsed_minutes
,chrg_per_minute as rate
from phonecall
) calls
,customer
where customer.cust_id = calls.cust_id
group by customer.cust_id, customer.cust_area_code, customer.cust_number, calls.cust_id
order by customer.cust_id asc
However on the last line instead of ordering it by customer.cust_id i would like to order it by "total cost of calls" however when ever i try and order it by this i get an error.
Do i need to assign it to another var before i use it in an order clause?
ThanksI wrote about [url http://forums.oracle.com/forums/click.jspa?searchID=5648765&messageID=1739843]the order of evaluating on select statement recently.
On the logical, select statement is evaluated in th following order.
[1-1] from
[1-2] on (joining)
[2-1] where (joining)
[2-2] start with, connect by
[2-3] where (excluding joining)
[3] group by
[4] having
[5] select
[6] union, union all, minus, intersect
[7] order by
The alias can be referred predefined in this order, but cannot be referred same level or post-defined. In subquery, this principle is affected as same also.
The table alias and/or the column alias on [1-1] 'from' can be referred all level excluding [1-1], but cannot be referred in inline view (subquery) on [1-1] 'from'.
select xxx from tab1 a1,(select xxx2 from tab2 a2 where a2.xxx=a1.xxx) -- No Good (This is same level)
select a1,a2 from (select xxx a1, xxx2 a2 from tab1) -- Good
select * from (select xxx a1, xxx2 a2 from tab1) -- Good, * explode to a1,a2
The column alias on [5] 'select' only can be referred on [7] 'order by'.
select xxx a1, xxx2 a2,count(*) from tab1 group by a2 -- No Good (post defined)
select xxx a1, xxx2 a2,count(*) from tab1 order by a2 -- Good
The naming rule of alias must accord with [url http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements008.htm#i27561]Schema Object Names and Qualifiers.
So, the alias enclosed by double quotation mark becomes case sensitive.
In additional, in order-by-clause, we can specified column number on select-clause.
select empno,ename,sal from scott.emp order by 3; -- this means order by sal -
Hi,
I have another query running slow when executed from cognos. It is also not returning any output continues to execute,
with "Union15" as (
select distinct CASE WHEN(substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 1, 4)||case substr(to_char(FLOOR("EES_ENERGY_MASTER"."DISC_MON"/100)), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END "QUARTER", "EES_ENERGY_MASTER"."PAT_KEY" "Cases_Using_Energy", 0 "Total_Cases"
from "MDM_DBA"."EES_ENERGY_MASTER" "EES_ENERGY_MASTER", "MDM_DBA"."EES_CONS_PROV" "EES_CONS_PROV"
where "EES_ENERGY_MASTER"."DISC_MON">=2006101 and "EES_ENERGY_MASTER"."PDCT_CAT"='Energy' and substr("EES_ENERGY_MASTER"."ICD_CODE", 1, 2)='68-gyn' and "EES_ENERGY_MASTER"."MANUFACTURER"='EES' and "EES_CONS_PROV"."CONS_06_09_YN" in ('N', 'Y') and "EES_ENERGY_MASTER"."PROV_ID"="EES_CONS_PROV"."PROV_ID" union
select CASE WHEN(substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4)||case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END "QUARTER", 0 "Cases_Using_Energy", count("MVW_EES_ICD_STATS"."CASES") "Total_Cases"
from "MDM_DBA"."MVW_EES_ICD_STATS" "MVW_EES_ICD_STATS", "MDM_DBA"."EES_CONS_PROV" "EES_CONS_PROV", "MDM_DBA"."EES_HOSP_CHG_PROV" "EES_HOSP_CHG_PROV"
where "MVW_EES_ICD_STATS"."DISC_QTR">=20061 and "MVW_EES_ICD_STATS"."ICD_GROUP"='68-gyn' and "EES_CONS_PROV"."CONS_06_09_YN" in ('N', 'Y') and "EES_HOSP_CHG_PROV"."PDCT_CAT"='Energy' and "EES_HOSP_CHG_PROV"."MANUFACTURER"='EES' and "MVW_EES_ICD_STATS"."PROV_ID"="EES_CONS_PROV"."PROV_ID" and "MVW_EES_ICD_STATS"."PROV_ID"="EES_HOSP_CHG_PROV"."PROV_ID"
group by CASE WHEN(substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4) IS NULL) OR (case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end IS NULL) THEN NULL ELSE (substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 1, 4)||case substr(to_char(FLOOR("MVW_EES_ICD_STATS"."DISC_QTR")), 5, 1) when '1' then 'Q1' when '2' then 'Q2' when '3' then 'Q3' when '4' then 'Q4' end ) END)
select "T1"."C0" "levelkey", "T1"."C1" "Cases_Using_Energy", "T0"."C0" "Cases_Using_Energy1", "T1"."C2" "Total_Cases"
from (
select count(distinct "Union15"."Cases_Using_Energy") "C0"
from "Union15") "T0", (
select "Union15"."QUARTER" "C0", count(distinct "Union15"."Cases_Using_Energy") "C1", sum("Union15"."Total_Cases") "C2"
from "Union15"
group by "Union15"."QUARTER") "T1"The explain plan is as follows,
PLAN_TABLE_OUTPUT
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
| 0 | SELECT STATEMENT | | 1 | 50 | | 22 |
| 2 | TEMP TABLE TRANSFORMATION | | | | | |
| 1 | RECURSIVE EXECUTION | SYS_LE_2_0 | | | | |
| 0 | INSERT STATEMENT | | 3053 | 128K| | 1372 |
| 1 | LOAD AS SELECT | | | | | |
| 2 | SORT UNIQUE | | 3053 | 128K| 376K| 1372 |
| 3 | UNION-ALL | | | | | |
|* 4 | HASH JOIN | | 3052 | 128K| | 185 |
|* 5 | TABLE ACCESS FULL | EES_CONS_PROV | 622 | 3732 | | 2 |
|* 6 | TABLE ACCESS BY INDEX ROWID | EES_ENERGY_MASTER | 3055 | 110K| | 182 |
|* 7 | INDEX RANGE SCAN | IDX_ENERGY_PDCT_CAT | 1978 | | | 2478 |
| 8 | SORT GROUP BY | | 1 | 40 | | 1160 |
|* 9 | TABLE ACCESS BY INDEX ROWID | EES_HOSP_CHG_PROV | 4 | 72 | | 1 |
| 10 | NESTED LOOPS | | 1 | 40 | | 1157 |
| 11 | NESTED LOOPS | | 1 | 22 | | 1156 |
|* 12 | TABLE ACCESS BY INDEX ROWID| MVW_EES_ICD_STATS | 1 | 16 | | 1155 |
|* 13 | INDEX RANGE SCAN | MVWICDSTATS_DISCQTR_IDX | 13M| | | 26068 |
|* 14 | TABLE ACCESS BY INDEX ROWID| EES_CONS_PROV | 1 | 6 | | 1 |
|* 15 | INDEX UNIQUE SCAN | EES_CONS_PROV_PK | 1 | | | |
|* 16 | INDEX RANGE SCAN | PROV_ID_IDX_2 | 65 | | | 1 |
| 3 | MERGE JOIN CARTESIAN | | 1 | 50 | | 22 |
| 4 | VIEW | | 1 | 13 | | 3 |
| 5 | SORT GROUP BY | | 1 | 13 | | |
| 6 | VIEW | | 3053 | 39689 | | 3 |
| 7 | TABLE ACCESS FULL | SYS_TEMP_0FD9D68B3_C112F95D | 3053 | 110K| | 3 |
| 8 | VIEW | | 1 | 37 | | 19 |
| 9 | SORT GROUP BY | | 1 | 37 | | 19 |
| 10 | VIEW | | 3053 | 110K| | 3 |
| 11 | TABLE ACCESS FULL | SYS_TEMP_0FD9D68B3_C112F95D | 3053 | 110K| | 3 |
Predicate Information (identified by operation id):
4 - access("EES_ENERGY_MASTER"."PROV_ID"="EES_CONS_PROV"."PROV_ID")
5 - filter("EES_CONS_PROV"."CONS_06_09_YN"='N' OR "EES_CONS_PROV"."CONS_06_09_YN"='Y')
6 - filter("EES_ENERGY_MASTER"."DISC_MON">=2006101 AND SUBSTR("EES_ENERGY_MASTER"."ICD_CODE",1,2)='68-gyn'
AND "EES_ENERGY_MASTER"."MANUFACTURER"='EES')
7 - access("EES_ENERGY_MASTER"."PDCT_CAT"='Energy')
9 - filter("EES_HOSP_CHG_PROV"."PDCT_CAT"='Energy' AND "EES_HOSP_CHG_PROV"."MANUFACTURER"='EES')
12 - filter("MVW_EES_ICD_STATS"."ICD_GROUP"='68-gyn')
13 - access("MVW_EES_ICD_STATS"."DISC_QTR">=20061 AND "MVW_EES_ICD_STATS"."DISC_QTR" IS NOT NULL)
14 - filter("EES_CONS_PROV"."CONS_06_09_YN"='N' OR "EES_CONS_PROV"."CONS_06_09_YN"='Y')
15 - access("MVW_EES_ICD_STATS"."PROV_ID"="EES_CONS_PROV"."PROV_ID")
16 - access("MVW_EES_ICD_STATS"."PROV_ID"="EES_HOSP_CHG_PROV"."PROV_ID")
Please help with some solution.OK: the third parameter of the SUBSTR function indicates the (maximum) length of the returnd string.
Therefore SUBSTR("EES_ENERGY_MASTER"."ICD_CODE",1,2) could possibly be '68' , but never '68-gyn'.
'68-gyn' is just 4 characters too long.
Urs -
Improve Performance on Inline view Query
All,
I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
ex:
SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
but this design was rejected, because it seems to have a great impact on performance due to inline view.
Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
please help to find a alternative solution which helps to get the expected result set and same time without loosing performancebut this design was rejected, because it seems to have a great impact on performance due to inline view.What proof was offered that this query performed badly. There is nothing inherently non-performant about in-line views. I would demand to see some evidence that this query uses an unreasonable amount of system resource.
However, you could try this:
SELECT t.col1, avg(t.col2)
FROM t1 t
WHERE t.col1 IN ( SELECT DISTINCT x.col1
FROM t1 x
WHERE col3 = 'XXX'
AND rownum <=10 )
GROUP BY t.col1
/I assume your example is not derived from your real code (otherwise the WHERE clause would restrict the inline query to one returned row - problem solved!)
Cheers, APC -
Help with Inner Join query in SQL
Hope someone can help with this, as this is quite an involved project for me, and I'm just about there with it.
My table structure is :
table_packages
packageID
package
packageDetails
etc
table_destinations
destinationID
destination
destinationDetails
etc
table_packagedestinations
packageID
destinationID
..so nothing that complicated.
So the idea is that I can have a package details page which shows the details of the package, along any destinations linked to that package via the packagedestinations table.
So this is the last part really - to get the page to display the destinations, but I'm missing something along the way....
This is the PHP from the header, including my INNER JOIN query....
PHP Code:
<?php
$ParampackageID_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
$ParamSessionpackageID_WADApackages = "-1";
if (isset($_SESSION['WADA_Insert_packages'])) {
$ParamSessionpackageID_WADApackages = (get_magic_quotes_gpc()) ? $_SESSION['WADA_Insert_packages'] : addslashes($_SESSION['WADA_Insert_packages']);
$ParampackageID2_WADApackages = "-1";
if (isset($_GET['packageID'])) {
$ParampackageID2_WADApackages = (get_magic_quotes_gpc()) ? $_GET['packageID'] : addslashes($_GET['packageID']);
mysql_select_db($database_connPackages, $connPackages);
$query_WADApackages = sprintf("SELECT packageID, package, costperpax, duration, baselocation, category, dateadded, agerange, hotel, educational_tours, field_trips, corporate_outings, plant_visits, budget_package, rollingtours, teambuilding, description, offer FROM packages WHERE packageID = %s OR ( -1= %s AND packageID= %s)", GetSQLValueString($ParampackageID_WADApackages, "int"),GetSQLValueString($ParampackageID2_WADApackages, "int"),GetSQLValueString($ParamSessionpackageID_WADApackages, "int"));
$WADApackages = mysql_query($query_WADApackages, $connPackages) or die(mysql_error());
$row_WADApackages = mysql_fetch_assoc($WADApackages);
$totalRows_WADApackages = mysql_num_rows($WADApackages);
$colname_educationalDestinations = "1";
if (isset($_GET['PackageID'])) {
$colname_educationalDestinations = (get_magic_quotes_gpc()) ? packageID : addslashes(packageID);
mysql_select_db($database_connPackages, $connPackages);
$query_educationalDestinations = sprintf("SELECT * FROM destinations INNER JOIN (packages INNER JOIN packagedestinations ON packages.packageID = packagedestinations.packageID) ON destinations.destinationID = packagedestinations.destinationID WHERE packages.packageID = %s ORDER BY destination ASC", GetSQLValueString($colname_educationalDestinations, "int"));
$educationalDestinations = mysql_query($query_educationalDestinations, $connPackages) or die(mysql_error());
$row_educationalDestinations = mysql_fetch_assoc($educationalDestinations);
$totalRows_educationalDestinations = mysql_num_rows($educationalDestinations);
?>
And where I'm trying to display the destinations themselves, I have :
<table>
<tr>
<td>Destinations :</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_educationalDestinations['destination']; ?></td>
</tr>
<?php } while ($row_educationalDestinations = mysql_fetch_assoc($educationalDestinations)); ?>
</table>
If anyone could have a quick look and help me out that would be much appreciated - not sure if its my SQL at the top, or the PHP in the page, but either way it would be good to get it working.
Thanks.First off, you need to get the database tables so that there is a relationship between them.
In fact, if there is a one to one relationship, then it may be better to store all of your information in one table such as
table_packages
packageID
package
packageDetails
destination
destinationDetails
etc
If there is a one to many relationship, then the following would be true
packages
packageID
package
packageDetails
etc
destinations
destinationID
packageID
destination
destinationDetails
etc
The above assumes that there are many destinations to one package with the relationship coloured orange.
Once you have the above correct you can apply your query as follows
SELECT *
FROM packages
INNER JOIN destinations
ON packages.packageID = destinations.packageID
WHERE packages.packageID = %s
ORDER BY destination ASC
The above query will show all packages with relevant destinations -
Need help with LikeFilter for querying the keyset instead of value
Hi,
I'm looking for help with the LikeFilter.
I need to query the cache to get all entries with key starting with a particular string.
I could see samples using LikeFilter for querying the values in the cache but not the keyset.
Can someone help?
E.g:
Cache Entries:
abc123 - value1
abc234 - value2
bcd123 - value3
I want to get all entries with key starting with 'abc'.
thanks,
rama.NJ, thanks for the quick reply.
I tried something similar (as below) but this code gives me 'java.lang.NoClassDefFoundError: com/tangosol/util/ValueExtractor'.
KeyExtractor extractor = new KeyExtractor("getKey");
Filter filter = new LikeFilter(extractor, id+":%",'-',false);
-rama.
Edited by: 911950 on Feb 2, 2012 1:18 PM -
Need Help with Crystal viewer and ActiveX
Hi !!
I have a problem that i cant seem to be able to solve. I had alot of help from the forum but i think i got everything mixtup now...
From my addon i can print with CrystalReport Viewer or i cant print a Crystal report directly to my default printer, so thats good and working well. The problem is with Crystal Viewer that drags on the SBO screen and stays on the task bar.
It is strongly recommended to use an Activex to display my Crystal Viewer report. I tried so many differrent ways allways ending up with class id errors, or private class errors.
My report is called c:\report.rpt
My Working CrystalViewer form is called 'frmCRV'
Can some one help me thru this last step... I tried with the Activex sample in SDK but i think i dont have to use the Tree function ??? am i right ??
I'm running on SBO 2005 SP1 PL3
Crystal Report .net V10 and .net for code.
Thanks you all for your patience.Hi Again !
I can now open a form with an Activex part but i cant pass my CrystalViewer in it. Always says specified cast not valid.
Thanks -
Hi,
I've got a server audit log in PowerPivot (114,000 rows) which I provide some basic reporting from (PowerPivot is not my specialist subject so go easy). What I now need to perform a Distinct filter, but can't get the logic right. Basically the log
as two bits of information, 1) is the source of the job and 2) if it was a success or failure. What I need to do is to find all of the Source items that have never completed sucessfully. Any ideas on what formula is best to use, or
do I need to split in to multiple sheets and create a table relationship?
Source,Status
======,======
Source1,Fail
Source1,Fail
Source1,Success
Source2,Fail
Source3,Fail
Source3,Success
So in the above example, I would only expect the filter to show me Source2
Thanks
AlexHi Alex,
using Power Query instead, it would work like this:
Once you've pushed your table to PQ, add a column "helper" with value=1.
Then pivot on "Status", taking "helper"-column into "values column"
(hope translation is understandable, as I'm using localized Version & translation via "Quick info" isn't working in the PQ menu)
Then filter on column "Success" = blank.
Imke -
I have the following table
EX_ID
EX_NAME
EX_SURNAME
EX_FLAG
1
TOM
JONES
Y
1
JIM
SLIM
N
1
BO
SELECTA
Y
2
AIRES
BEARS
N
2
JIM
DAVIES
Y
3
PAUL
BALL
N
3
YOU
KNOW
N
I need to create a query that only displays one of the ex_id’s, it doesn’t matter which one. When the query has been run it will look like below:
EX_ID
EX_NAME
EX_SURNAME
EX_FLAG
1
TOM
JONES
Y
2
AIRES
BEARS
N
3
YOU
KNOW
N
Can anyone help with this query?SELECT * FROM
SELECT *,ROW_NUMBER () OVER (PARTITION BY ex_id ORDER BY (SELECT 0))
FROM tbl
) AS Der WHERE rn=1
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Maybe you are looking for
-
How to check special characters in view
hi, I have a field in view,in which want to check the field value doesnt contain any special characters. the field is a char field and it is not associated to any specific data element. Can u please help me in this reg. Regards, Saujanya
-
Hi all, I have a problem when i filter ALV column, which has data type BELNR (FI doc No). I input in filter FI doc: 40000007 (8 char long, w/o zero ahead), then i get the empty result. The really one i want to get is a ALV line with FI doc = '400000
-
I have successfully synced my music and a TV show but when I try to load my photos all I get is the "Apple TV is syncing" message and the revolving icon next to the Apple TV under devices. It will sometimes load a few photos from 1 or 2 small folders
-
Two days ago, I started getting a flurry of business-type emails from complete strangers to my BB address. But the address shown as me wasn't even my BB address. If my BB address is [email protected], they were all addressed to [email protected] Yest
-
Visual Swing Designer (for Eclipse)
Hi there We've developed a client software with JBuilder. Now we want to move the whole project to eclipse. Is there a good plugin for Eclipse to design Swing applications? I haven't found one so far. JBuilder has a Swing designer, and it is very usa