Confused with SQL query plan numbers
Hi all
I'm on Oracle 11.2 "Standard Edition" under Windows.
Here is a simple query plan and the predicate shown after the plan. I'm a little confused by the numbers indicated on the plan and not able to understand why the index is not used. The query is generated from Cognos front end, I captured using dbms_xplan.display_cursor (when the query was actually being run).
SQL > select * from table (dbms_xplan.display_cursor ('& sqlid', 0));
Enter the value of sqlid: 8yd0uu78jzqpg
old 1: select * from table (dbms_xplan.display_cursor ('& sqlid', 0))
new 1: select * from table (dbms_xplan.display_cursor('8yd0uu78jzqpg',0))
PLAN_TABLE_OUTPUT
------------------------------------------------------------------------------------------------------------------------------------
SQL_ID, 8yd0uu78jzqpg, number of children 0
-------------------------------------
Select distinct CASE WHEN (CASE WHEN ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" IS "
NULL NULL) THEN ELSE ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" | " -") END IS NULL)"
OR ("MY_TRANSACTION_TABLE3". ("' EMP_NM ' IS NULL) THEN NO OTHER (CASE
WHEN ("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" IS NULL), THEN ANOTHER NULL "
("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" | " -")
END | "" MY_TRANSACTION_TABLE3 ". ("" EMP_NM END ")"Officer_Name. "
'MY_TRANSACTION_TABLE3 '. ' ' NEW_OFFCR_CD ' 'Officer_Code' of
'FDS_LDN_APLOWNER '. ' ' MY_TRANSACTION_TABLE ' 'MY_TRANSACTION_TABLE3' where
'MY_TRANSACTION_TABLE3 '. » M » (« A », « E », « U », « F ») et
'MY_TRANSACTION_TABLE3 '. ' BASE_DT ' =: PQ1 and.
'MY_TRANSACTION_TABLE3 '. "" NEW_OFFCR_CD "as 'LO %' order by
'Officer_Code' asc nulls last
Hash value of plan: 1213358407
--------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 42146 (100) | |
| 1. UNIQUE FATE | | 230. 5750 | 42145 (1) | 00:08:26 |
|* 2 | TABLE ACCESS FULL | MY_TRANSACTION_TABLE | 4283. 104K | 42144 (1) | 00:08:26 |
--------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
2 filter (("MY_TRANSACTION_TABLE3". "NEW_OFFCR_CD" AS "% LO %' AND
'MY_TRANSACTION_TABLE3 '. ' BASE_DT ' =: PQ1 AND.
INTERNAL_FUNCTION ("MY_TRANSACTION_TABLE3". "M") AND "
'MY_TRANSACTION_TABLE3 '. (("' NEW_OFFCR_CD ' IS NOT NULL))
MY_TRANSACTION_TABLE has 1.3 million records. There is an index made up of 4 columns, first column is BASE_DT and none of the other columns is used here in the predicate.
Questions-
(1) the number the ROWS column in the plan, I guess it's number of selected records in the query (and not the records read by the query). Fix?
(2) there is an index on this table from BASE_DT (but other 3 columns in the index are not used). Each base_dt will select approximately 1.3 M. 80000 records why the index is not used?
(3) the column of time in the plan. Step 1 made by 08:26 minutes and not 2A crossed 08:26 minutes? or steps 1 and 2 together have 08:26 mins?
Thanks in advance
1 LINES - shows the no. of rows estimated by the optimizer for this operation. This estimate is made using the table and column statistics (+ a few formulas can be)
2. with the help of the index is decided by the optimizer based on profit he would get him. Internally, the database comes up with a lot of plan and selects a plan and at low cost. She stated that in light of current statistics rather than index, scanning, beneficial full table scan - so index have not been used.
3. it is worth cumulative - CBO estimated a total 08:26 minutes - similar to the cost. But this chronology may not be necessarily the actual execution time.
Read this link: http://www.oracle.com/technetwork/database/bi-datawarehousing/twp-explain-the-explain-plan-052011-393674.pdf it has almost all the information about the execution plan.
Tags: Database
Similar Questions
-
Help with SQL Query (Subselects)
Hello community,
IAM a new Member in this forum. The first excuse my English, my native language is German.
In my workplace, we have a great Orcle Database 11 g with 30 different tables for production control issues.
I try to get a couple of different information from the database, so I started with SQL of the query, but for this problem, I wasn't able to write a query to work.
In this case, I have 2 tables:
Table 1:
ID; ORDER_NR; DESCRIPTION; CREATE_DATE
1; A500236; CLEAN HOUSE; 20/02/2012
2; A623555; REPAIR CAR; 10/01/2012
3; A866944; MAINTAIN EQUIPMENT; 11/02/2012
Table 2:
ID; ORDER_NR; WO_STEP; STEP_DATE; EMPLOYEE
1; A500236; A; 21/02/2012; W0010
2; A500239; F; 21/02/2012; W0010
3; A500239; S; 22/02/2012; W0027
4; A500239; R; 23/02/2012; H0034
5; A500239; U; 25/02/2012; L0099
6; A263555; A; 15/01/2012; G0009
7; A263555; C; 17/01/2012; S0039
5 V A263555; R; 18/01/2012; K0059
9; A263555; U; 19/01/2012; A0048
10; A866944; A; 13/02/2012; H0034
11; A866944; B; 13/02/2012; L0035
12; A866944; G; 17/02/2012; D0084
13; A866944; U; 23/02/2012; S0039
And the result of my query should look like this:
ORDER_NR; DESCRIPTION; CREATE_DATE; A_STAT_AGE; R_STAT_AGE; U_STAT_AGE
A500236; OWN HOME; 20/02/2012; 5; 3; 1
A623555; REPAIR CAR; 01/10/2012; 42; 39; 38
A866944; MAINTAIN EQUIPMENT; 11/02/2012; 15; 4; 3
The age of my query result should be calculated from the date of the creation of the order.
I would like to know 2 things, one is how old was the order when they reached this status, R and U.
The second, that is, how long did you order remaining on A stat, R and U (and if possible all the others too)
It can happen that not every order reaches every State, so he ca go directly from A you in this case I want to display a generic character in this row/column
I hope you all know what I mean and what result to expect.
Thanks for your help.
Reinhard W.Hi, Reinhard,
990524 wrote:
Hi Frank,.I thank you for your professional response and excuse my non-professional way to clarify my question.
I have now already read and understand how to ask good questions, but is there an easy an inexpensive way to run a database on my computer at home?You can download the Oracle database from this site. The Express edition is easier to install. It lacks a few features that the Enterprise edition (for example, partitioning table and safety of level line), but most of the things work in all editions of Oracle.
All editions are free if you do not use them for Production applications. Of course, at this price (or lack thereof), you get Oracle support.I have already noticed that the syntax SQL for Oracle differ from other DBMSS.
Yes and some features are different in different products.
Your query works perfectly, thank you.
Now I want to refine my (your) query, is there a way to display a range of day within 1 day? As 0.5 day to half a day between two State timestamp.
Of course, you can do it. After the exact output desired of the sample data that I posted. If the sample data do not show what you need to do, then after a few different examples of data that makes.
My table contains the Date and time in a row, I forgot to mention that.
After a CREATE TABLE statement. I was guessing a lot of things that may be important. For example, I assumed you were using a DATE for date and time column. So it is only reasonable to do so, but maybe it's not what looks like at your table.
I tried something like this:
SYSDATE - MIN ( CASE WHEN t2.wo_step = 'A' THEN t2.step_date END ) AS Age_A
But it gives me an error of arithmetic overflow and not die difference in the Date and time or days with decimal friction.
There are only about 5.4 million possible days with DATEs of Oracle. Is only 7 digits and Oracle can treat approximately 39 numbers without overflow errors, so I don't see how this can happen if t2.step_date is really a DATE. This is an example of why you need to publish a CREATE TABLE statement.
-
How do I get the data of "Regulatory BOM" Formulation with SQL query output
Hello
We would like to implement a State of BiPublisher that displays "Regulation BOM" (wording-> click on TAB Formulation on exit Popup-> TAB Composition) information table.
How could get us this information with an SQL query?
Thank you
Annarosa
Hi, given 'Regulatory BOM' output of the Formulation are more complicated than expected. Attached is an example. You can test and make the appropriate changes to your report.
-
need help with sql query dates
Hello
I have a sql query I need to extract some info between data dates. Where clause in this query is:
WHERE CPD_BUS_UNIT =: ESI_PRM_1
AND CPD_VOUCHER_DATE > =: P_DATE_FROM
AND CPD_VOUCHER_DATE < (: P_DATE_TO + 1).
When I run the query into a toad, I can view the data, but not the execution plan. It gives an error ORA-00932 inconsistent Datatypes.
But when I remove (+ 1): P_DATE_TO, I can c the execution plan and data. The data will be different from the previous.
Please suggest how to rewrite the query.Can you please give it a try?
WHERE CPD_BUS_UNIT=:ESI_PRM_1 AND CPD_VOUCHER_DATE >= :to_date(P_DATE_FROM) AND CPD_VOUCHER_DATE < (to_date(:P_DATE_TO)+1)
Concerning
-
Help me with SQL Query to retrieve data from a view
Hello Guru,
I need help in my sql query.
I use SQL TeraData.
I want an Oracle result in the following form-
Open tickets
Open months failure / Repair Service s/o improvement request Total general
2009-01-2 4 4 5 15
2009-02 1 0 2 3 6
2009-03 4 1 2 2 9
Grand Total 7 5 8 10 30
I wrote the query as where - TIME_PERIOD, RQST_TYPE_DM and DEMAND_SUMMARY_FCT are the points of view and I extract the data from the views only.
Select NVL (CA. TIME_PERIOD. PERIOD_CD, 'Total') THAT year.
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% of Break' THEN 1 END) as BreakFix
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'N/a', 1 END) by n/a
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC as 'Improvement' THEN 1 END) accessories
COUNT (CASE WHEN CA. RQST_TYPE_DM. RQSTTYP_DESC Like '% Service' THEN 1 END) as ServiceRequests
COUNT (CA. RQST_TYPE_DM. RQSTTYP_DESC) AS grand_total
FROM CA. TIME_PERIOD, CA. RQST_TYPE_DM, CA. DEMAND_SUMMARY_FCT
WHERE (CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = CA. RQST_TYPE_DM. RQSTTYP_ID)
AND (CASE
WHEN CA. DEMAND_SUMMARY_FCT. MONTH_ID = CA. TIME_PERIOD. PERIOD_ID, 1
WHEN {fn concat ({fn concat (SUBSTR (CA. TIME_PERIOD. {(PERIOD_CD, 3, 4),'-')}, SUBSTR (CA. TIME_PERIOD. PERIOD_CD, 7, 2))} BETWEEN ' 2009-01' AND ' 2009-03' THEN 1
WHEN CA. DEMAND_SUMMARY_FCT. RQSTTYP_ID = '1' then 1
END) = 1
GROUP BY ROLLUP (CA. TIME_PERIOD. PERIOD_CD)
After executing the query, I get the following error:
3076: syntax Error: Data Type 'Time' does not match a defined Type name.
:( Kindly help me with this and let me know where I'm wrong... Please.Messages indicates something wrong with your data... It would seem that the data does not match your format mask.
Thus, the data or the format mask.
-
Need help with sql query performance
Dear all,
I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.
Select rownum LINE_NUM,
A.LINE_ID,
TO_CHAR (A.INVITMID),
TO_NUMBER (A.PICKQTY),
UNLOADINGPNT NULL,
RRNUM NULL,
WORKORDNUM NULL,
WORKORDDESC NULL,
A.PONUM,
DTR_DUMB NULL,
A.DESCRIPTION,
FROM_SUB NULL,
TO_SUB NULL,
NO SOURCE,
ASSET_NUMBER NULL,
A.RECEIPTNUM,
MOVEORD NULL,
FROM_LOC NULL,
TO_LOC NULL,
MSD_NUM NULL,
CONTAIN_LINE NULL,
A.UOM,
A.PO_RELEASE
de)
Select headerid Po.Po_Header_Id,
rcv1. Po_Line_Id LINE_ID,
rcv1.item_id INVITMID,
(NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,
Po.Segment1 PONUM,
Rcv1.Receipt_Num RECEIPTNUM,
Rcv1.Item_Desc DESCRIPTION,
Rcv1.Transact_Uom GLU,
Rcv1.Po_release
Po_Headers_All in.,.
(Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "EXPENSES".
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
UNION ALL
SELECT A.Po_Header_Id,
C.RECEIPT_NUM receipt_num,
A.Po_Line_Id,
A.Destination_Type_Code,
B.Item_Id,
B.item_description Item_Desc,
A.UNIT_OF_MEASURE Transact_Uom,
A.QUANTITY Transact_Qty,
D.RELEASE_NUM PO_RELEASE
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND B.ITEM_ID IS NULL
AND UPPER (A.Transaction_Type) = "to DELIVER".
AND higher (A.Destination_Type_Code) = "WORKSHOP".
D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3
GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),
(SELECT A.PO_LINE_ID,
Sum (A.Quantity) transact_qty,
A.PO_HEADER_ID,
C.RECEIPT_NUM
OF RCV_TRANSACTIONS,.
RCV_SHIPMENT_HEADERS C.
B RCV_SHIPMENT_LINES,
PO_RELEASES_ALL D
WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID
AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID
AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"
AND D.PO_RELEASE_ID = A.PO_RELEASE_ID
A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2
Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)
And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)
And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)
And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)
Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has
Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
Please find the attached PLAN to EXPLAIN.
Thank you
May be essentially the same join (between a, b, c and d) twice instead of three times
sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2
We can work on what we can see only
Select rownum line_num,
rcv1.po_line_id line_id,
TO_CHAR (rcv1.item_id) invitmid,
NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,
unloadingpnt null,
rrnum null,
workordnum null,
workorddesc null,
Po. Ponum Segment1,
dtr_dumb null,
description of the rcv1.item_desc,
from_sub null,
to_sub null,
No source,
asset_number null,
rcv1.receipt_num receiptnum,
moveord null,
from_loc null,
to_loc null,
msd_num null,
contain_line null,
Glu rcv1.transact_uom,
rcv1.po_release
of po_headers_all in.
left outer join
(select a.po_header_id,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description item_desc,
a.unit_of_measure transact_uom,
Sum (a.Quantity) transact_qty,
d.release_num po_release
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
po_line_id,
destination_type_code,
unit_of_measure,
quantity
of rcv_transactions
where upper (a.transaction_type) = "to DELIVER".
and upper (a.destination_type_code) ('charge', 'WORKSHOP')
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
where upper (a.destination_type_code) = "EXPENSES".
or (upper (a.destination_type_code) = 'WORKSHOP'
and b.item_id is null
)
A.po_header_id group,
c.receipt_num,
a.po_line_id,
a.destination_type_code,
b.item_id,
b.item_description,
a.unit_of_measure,
d.release_num
) rcv1
On po.po_header_id = rcv1.po_header_id
left outer join
(select a.po_line_id,
Sum (a.Quantity) transact_qty,
a.po_header_id,
c.receipt_num
from (select shipment_header_id,
shipment_line_id,
po_release_id,
po_header_id,
quantity
of rcv_transactions
where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.
) a
inner join
rcv_shipment_lines b
On a.shipment_line_id = b.shipment_line_id
inner join
c rcv_shipment_headers
On a.shipment_header_id = c.shipment_header_id
left outer join
po_releases_all d
On a.po_release_id = d.po_release_id
A.po_line_id group,
a.po_header_id,
c.receipt_num
) rcv2
On rcv1.po_line_id = rcv2.po_line_id
and rcv1.receipt_num = rcv2.receipt_num
where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)
Concerning
Etbin
-
Dear all,
I have a sql like query below
SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER
MTL_TXN_REQUEST_HEADERS D,.
MTL_TXN_REQUEST_LINES, E.
MTL_MATERIAL_TRANSACTIONS G,.
Mtl_Transaction_Types I have
WHERE D.HEADER_ID = E.HEADER_ID
AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID
AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')
AND E.LINE_ID = G.MOVE_ORDER_LINE_ID
AND D.MOVE_ORDER_TYPE = 5
TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')
D.REQUEST_NUMBER GROUP
I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.
above query is back under results
If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.
so in the example above, it must return
FIRST REQUEST NUMBER LAST NUMBER
2383 1886
Thank you
select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max from ( select min(g.transaction_date) transaction_date , d.request_number from mtl_txn_request_headers d , mtl_txn_request_lines e , mtl_material_transactions g , mtl_transaction_types i where d.header_id = e.header_id and g.transaction_type_id = i.transaction_type_id and upper(i.transaction_type_name) = upper('WIP Issue') and e.line_id = g.move_order_line_id and d.move_order_type = 5 and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014') group by d.request_number )
-
Help with SQL query for SQL experts!
Hi all
For the very expert on SQL.
------------------
create table t1 (STEP number);
Insert into t1 select rownum from dba_tables where rownum < 11;
commit;
create table t2 (the STEP number, name varchar2 (4), varchar2 (1)) of the State;
insert into t2 values (1, 'TOTO', ' A');
insert into t2 values (3, 'TOTO', 'C');
insert into t2 values (4, 'TOTO', ');
insert into t2 values (1, 'FIFI', ' A');
insert into t2 values (6, 'FIFI', 'B');
commit;
----------------
My goal is to list the STATE in the NAME of all the STEPS, even if measures do not exist for a NAME.
In other words, my query should return a result like this: (query on t1 and t2, of course)
STEP 1 2 3 4 5 6
TOTO A C D NO NO NO
FIFI HAS NO NO NO NO D
Thank you in advance.
with the data as)
Select
T1. Step step
name
State
Of
T1, t2
where
T1. Step = T2. Step (+)
)Select
*
from the data
Pivot (max (state))
for step (1,2,3,4,5,6,7,8,9,10)
)
where the name is not nullNAME 1 2 3 4 5 6 7 8 9 10 TOTO A - C D - - - - - - FIFI A - - - - B - - - - If the column name must be the stage instead of the name
with the data as)
Select
Step 1 T1. Step
name as step
State
Of
T1, t2
where
T1. Step = T2. Step (+)
)Select
*
from the data
Pivot (max (state))
for step 1 in (1,2,3,4,5,6,7,8,9,10)
)
where the step is not null -
Need help with SQL Query - change of name history of audit table.
I need your help to find the result in the following way...
Emp No New_name Old_Name ----------------------------------------------- 1 Name3 Name2 1 Name2 Name1
Thank you...create table emp(emp_id number(10), emp_name varchar(50), constraints emp_pk primary key(emp_id) ); create table emp_audit( audit_id number(10), emp_id number(10), emp_name varchar(50), audit_date date, constraints emp_audit_pk primary key (audit_id), constraints emp_audit_emp_fk foreign key(emp_id) references emp(emp_id)); insert into emp values(1,'Name3'); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy')); insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date) values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy')); commit;
Dipabkar Bédard (DB) wrote:
We write is the query without using "partition by" in oracle...?
with t as ( select audit_id, emp_id, emp_name, row_number() over(order by audit_id) rn from emp_audit order by emp_id, audit_id ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t a left join t b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ------------ 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
And without analytical functions:
with t1 as ( select audit_id, emp_id, emp_name from emp_audit order by emp_id, audit_id ), t2 as ( select audit_id, emp_id, emp_name, rownum rn from t1 ) select a.audit_id, a.emp_id, a.emp_name old_name, nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name from t2 a left join t2 b on ( b.emp_id = a.emp_id and b.rn = a.rn + 1 ) / AUDIT_ID EMP_ID OLD_NAME NEW_NAME ---------- ---------- -------------------------------------------------- ---------- 1 1 Name1 Name2 2 1 Name2 Name3 SQL>
SY.
-
Please help in the slot provided.
I have two columns A and B in a table with data as below,
A AND B
1 INACTIVE
ACTIVE 1
2 ACTIVE
DEFAULT 2
2 DEGENERATE
2 INACTIVE
3 PASSED
3 DEFAULT
3 DEGENERATE
3 DEGENERATE
INACTIVE 3
4 INACTIVE
DEFAULT 4
5 BY DEFAULT
5 ACTIVE
I want to write a query that will give the values in column A where column B must not have value as 'ACTIVE' after group the data in column A.
That is to say of the above example data that the outcome should be 3 and 4 since only 3 and 4 was not ACTIVE as a value in column B.
My database is version 11g 11.2.0.3 on OS linux.
nothing... just use
SELECT A
FROM THE DATA
Group by one
having MAX (CASE b WHEN "ACTIVE", THEN b ELSE NULL END) is null;
because you have a table named somehow (icies data) and you have columns in it with a name, I just don't want to create tables, insert data, and remove the tables afterwards - it's the reason why the with.
HTH
-
Help with sql query / a subquery to perform the COUNT
Hello everyone,
Co-worker colleague asked me to post a request here in hopes of getting more support. Here's the question:
There are 3 tables associated with this request. A table of the application, which displays a number of application open for a particular request, an audit table that shows you all employees who worked on this application and one employee who shows you the details of the employee table. My colleague is trying to understand what, how to see only applications that have been published by a wizard, but not a Manager. There are a few applications that worked on both, but he won't see this request in its results.
Here are the tables
EMP
ID FULL_NAME 1234 John Doe 5467 Jane Doe 2345 Clark Kent 5432 June Cleaver Unfortunately, this table does not have a title column (which was created provider, so we cannot change the internal structure). My colleague knows who is the Assistant and the Director, then in this case, the first two of the id:
1234 and 5467 are managers and the other 2 are assistants
T_APPLICATION
app_id app_number date_opened app_type 9018 54778 JANUARY 10, 2014 NETWORK 9019 54779 JANUARY 11, 2014 DATABASE 9010 55000 MARCH 12, 2014 MATERIAL T_APP_AUDIT
APP_ID PROCESSED_BY 9018 1234 9018 2345 9018 5432 9019 2345 9019 5432 9010 5432 So, here is the actual query, I was given: it is actually to check the number of times that each application has been published per person:
Select a.app_id, c.full_name, count (*) that controls
t_application a, t_app_audit b, c of the emp
where a.app_id = b.app_id and b.processed_by = c.id and
a.app_type in ('NETWORK', "DATABASE")
and b.processed not in ('1234, ' 5467')
GROUP OF A.APP_ID, c.full_name;
IF I won't see 9018 in my results, since at one time it was edited by a Manager (1234). Unfortunately, this request does not eliminate the app_id 9018, it eliminates only the name of handlers appear in the query. I hope I've explained this properly, and any help to point us in the right direction is welcomed. Thanks in advance.
Select
a.app_id
c.full_name
, count (*) as the controls
of t_application one
t_app_audit b
c of the emp
where a.app_id = b.app_id
and b.processed_by = c.id
and a.app_type in ('NETWORK', "DATABASE")
and b.app_id by (not in
Select app_id
of t_app_audit
where processed_by in ('1234, ' 5467')
)
GROUP OF A.APP_ID, c.full_name;
-
Hello all,.
I run the query below
Select c.name_line1, c.name_line2
of tabele c where dra_code = 115
and dus_num = 111111
The output of the query shows name_line1 = name of family and Name_line2 = first name and middle name.
I need help to change the query to return only the name of the Name_line2.
Trat kindly as urgentregexp_count(name, '[[:space:]]') = length(name) - length(replace(name,' '))
with data as ( select 'Last_Name First_Name' name from dual union select 'Last_Name First_Name Middle_Name' name from dual ) select CASE when length(name) - length(replace(name,' ')) = 1 then name ELSE substr(name, 1, regexp_instr(name, '[[:space:]]', 1, 2) - 1) END name from data; NAME -------------------------------- Last_Name First_Name Last_Name First_Name 2 rows selected.
Try to use the function REGEXP_COUNT returns the invalid identifier.
select * from v$version
set linesize 200 col name for a40 col name_edit for a40 col text1 for a20 col text2 for a20 col text3 for a20 with data as ( select 'LastName FirstName' name from dual union select 'LastName FirstName MiddleName' name from dual ) select name, CASE when length(name) - length(replace(name,' ')) = 1 then name ELSE substr(name, 1, regexp_instr(name, '[[:space:]]', 1, 2) - 1) END name_edit, regexp_substr(name||' ', '[[:alpha:]]+. ', 1, 1) text1, regexp_substr(name||' ', '[[:alpha:]]+. ', 1, 2) text2, regexp_substr(name||' ', '[[:alpha:]]+. ', 1, 3) text3 from data; NAME NAME_EDIT TEXT1 TEXT2 TEXT3 ---------------------------------------- ---------------------------------------- -------------------- -------------------- -------------------- LastName FirstName LastName FirstName LastName FirstName LastName FirstName MiddleName LastName FirstName LastName FirstName MiddleName 2 rows selected.
-
Need help with SQL query (10 years since I have SQL)
Hi guys,.
I tried to remove some rust SQL. I did not go to SQL within a certain time.
Here are the tables (% = ent $ = varcchar)
-----------------
RESULT
-----------------
% RESULT_ID-$ RC-% YEAR_ID - PERIOD_ID-% CONTRACT_NO-% value %
20841---1439---83---37---010427102---1
20842---1439---83---41---010427102---2
20843---1439---84---37---010427102---3
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
-----------------
YEARS
-----------------
YEAR_ID - YEAR_DESC
83 2010-2011
84 2011-2012
-----------------
PERIOD
-----------------
PERIOD_ID - PERIOD_DESC
34 14
37 02
41 03
What I want is to get the last period of each year in the RESULT table. (I'll work the rest of the WHERE statement myself, because I have omitted some news, or columns for simplicity)
Note that I can't rely on the ID of the period, as the chronological order is not respected.
In the scenario above, I should GET
% RESULT_ID-$ RC - YEAR_ID - PERIOD_ID-% CONTRACT_NO-% % value %
20844---1439---84---41---010427102---4
20845---1439---83---34---010427102---5
I have the following, but it only returns values if the year is the last time!
SELECT DISTINCT RESULTS. RESULT_ID, RESULT. RC, RESULT. PERIOD_ID, RESULT. YEAR_ID, RESULT. CONTRACT_NO, YEARS. YEAR_DESC
RESULT, YEARS
WHERE TO TRAIN. YEAR_ID = YEARS. YEAR_ID AND - it is my problem, I want the last period for each year.
RESULT. PERIOD_ID = (SELECT PERIOD_ID FROM PERIOD WHERE CAST (PERIOD_DESC AS INT) = (Select MAX (CAST (PERIOD_DESC AS INT)) of the period)) - I think it works fine I'm able to get the last period
ORDER BY YEARS. YEAR_DESC;
Published by: 935079 on May 17, 2012 11:32
Add space not formatted tabs
Published by: 935079 on May 17, 2012 11:35Your way to present the data that makes it very tedious to create test data. Next time please simply provide CREATE TABLE and INSERT statements so that we can all share the same test data.
Without test data, I think you want Frank solution with a very minor change: order value instead of id, then the number of line 1 is the highest value.
with GOT_R_NUM as ( SELECT r.* -- or list the columns you want , ROW_NUMBER() over(partition by R.YEAR_ID, R.CONTRACT_NO order by -- P.PERIOD_ID P.PERIOD_VALUE DESC NULLS LAST) AS r_num FROM result r JOIN period p ON r.period_id = p.period_id ) SELECT * -- or list all columns except r_num FROM got_r_num WHERE r_num = 1;
-
PROBLEM WITH SQL QUERY.
Hi all
I am executing the following query, which I use to retrieve unique records.
SELECT OH. ORDER_ID, OH. ORDER_DATE, OH. GRAND_TOTAL, OSI. DESCRIPTION ACE ORDER_STATUS,
PMT. DESCRIPTION AS PAYMENT_METHOD, TR. AS PAYMENT_STATUS DESCRIPTION
OF ORDER_HEADER OH INNER JOIN ORDER_PAYMENT_PREFERENCE OPP ON OH. ORDER_ID = OPP. ORDER_ID and
OPP. CREATED_DATE = (SELECT MAX (CREATED_DATE) OF ORDER_PAYMENT_PREFERENCE WHERE THE ORDER_ID = OH. ORDER_ID)
PAYMENT_METHOD_TYPE PMT, STATUS_ITEM SO, STATUS_ITEM OSI
WHERE OPP. PAYMENT_METHOD_TYPE_ID = PMT. PAYMENT_METHOD_TYPE_ID AND
OPP. BATCH = IF. BATCH AND OH. BATCH = OSI. BATCH AND
(OH. BATCH = "ORDER_CREATED" | OH. BATCH = "ORDER_HOLD") AND
OH. "CREATED_STAMP > = ' 2011-12-03 11:41:04.
Problem I am facing is, for some a few order_ids we have several entries in ORDER_PAYMENT_PREFERENCE with CREATED_DATE even where query return me of duplicate records.
I applied OPP. "CREATED_DATE = (SELECT MAX (CREATED_DATE) OF ORDER_PAYMENT_PREFERENCE WHERE THE ORDER_ID = OH. ORDER_ID)' forced to get the record, unique, but as I said to few recordings, we have several lines in ORDER_PAYMENT_PREFERENCE corr. ORDER_ID single and multiple records have same CREATED_DATE.
Can you suggest a few changes, the query to retrieve unique records.
I know I'm a very abstract information, shortly I'll provide table structure and little info I want in this query.
It's because of the tight work schedule.
Thank you
Jagdeep SinghHello
Basically, you need to convert a number in his order inside each created_date order_payment_preference. However, if you have more than one created_date which is him even you'll actually choose one of them at random unless you specify an order more squeezed by the clause. For example, you might have a numeric value from a sequence that could be added to determine which input was really the most recent. In any case the following should give you an idea what I mean...
SELECT order_id, order_date, grand_total, order_status, payment_method, payment_status FROM ( SELECT oh.order_id, oh.order_date, oh.grand_total, osi.description AS order_status, pmt.description AS payment_method, si.description AS payment_status ROW_NUMBER() OVER(PARTITION BY opp.order_id ORDER BY opp.created_date DESC) rn FROM order_header oh JOIN order_payment_preference opp ON oh.order_id = opp.order_id JOIN payment_method_type pmt ON opp.payment_method_type_id = pmt.payment_method_type_id JOIN status_item si ON opp.status_id = si.status_id JOIN status_item osi ON oh.status_id = osi.status_id WHERE AND oh.status_id IN('ORDER_CREATED','ORDER_HOLD') AND oh.created_stamp >= '2011-12-03 11:41:04' ) WHERE rn = 1
Some notes if - it is not a good idea to mix the styles of the junction between ansi and oracle style, it makes it difficult to follow. Just choose one or the other.
OH.STATUS_ID='ORDER_CREATED' || OH.STATUS_ID='ORDER_HOLD'
Makes no sense. I took a guess that you meant, OR then I converted to an IN clause that will do the same job.
HTH
David
-
Help with SQL query definition
Hello
Could someone please help me with the sub condition.
On the example of the EMP table, I want a report that looks like:
Please see the application for the relevant columns and the definitions of the watch below:Manager Tot_Joiniees_Q1 Tot_Joiniees_Q2 Tot_Joiniees_Q3 Tot_Joiniees_Q4
Thank youSELECT mgr, CASE WHEN TO_CHAR (hiredate, 'MON') IN ('JUN', 'JUL', 'AUG') THEN 'Q1' WHEN TO_CHAR (hiredate, 'MON') IN ('SEP', 'OCT', 'NOV') THEN 'Q2' WHEN TO_CHAR (hiredate, 'MON') IN ('DEC', 'JAN', 'FEB') THEN 'Q3' WHEN TO_CHAR (hiredate, 'MON') IN ('MAR', 'APR', 'MAY') THEN 'Q4' END qtd, COUNT (DISTINCT ename) FROM emp GROUP BY mgr, CASE WHEN TO_CHAR (hiredate, 'MON') IN ('JUN', 'JUL', 'AUG') THEN 'Q1' WHEN TO_CHAR (hiredate, 'MON') IN ('SEP', 'OCT', 'NOV') THEN 'Q2' WHEN TO_CHAR (hiredate, 'MON') IN ('DEC', 'JAN', 'FEB') THEN 'Q3' WHEN TO_CHAR (hiredate, 'MON') IN ('MAR', 'APR', 'MAY') THEN 'Q4' END ORDER BY 1, 2
CJMSELECT mgr Manager, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '1' then 1 end) Tot_Joiniees_Q1, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '2' then 1 end) Tot_Joiniees_Q2, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '3' then 1 end) Tot_Joiniees_Q3, COUNT(CASE WHEN TO_CHAR(hiredate,'Q') = '4' then 1 end) Tot_Joiniees_Q4 FROM emp GROUP BY mgr, TO_CHAR(hiredate,'Q') / MANAGER TOT_JOINIEES_Q1 TOT_JOINIEES_Q2 TOT_JOINIEES_Q3 TOT_JOINIEES_Q4 ---------- --------------- --------------- --------------- --------------- 7566 0 0 0 1 7839 0 3 0 0 7698 0 0 2 0 7788 0 1 0 0 7782 1 0 0 0 7566 0 1 0 0 7902 0 0 0 1 7698 2 0 0 0 0 0 0 1 7698 0 0 0 1 10 rows selected. SQL>
SY.
Maybe you are looking for
-
What iOS 10 will be updated to allow SMS texts to be sent from the iPhone? SMS text send an iPhone
-
L50 - A - 160:USB of power in standby mode satellite is disabled but it STILL works
Hi all! It's my L50-A-160. USB power standby is disabled in the BIOS but it always on!Nothing helps.As I can not turn off wakes on keyboard events. BIOS 1.30. Thanks for the advice in advance.
-
Hi guys. I recently bought a sony xperia m4 im really happy with it. But today all of a sudden it won't play the videos. Such as youtube. It is said "video cannot be played" the phone does all kinds of updates automatic I'm not sure what has been upd
-
How to back up a Web site to work offline using windows vista?
Original title: ' ideas: insert an error code or give a brief description of what you're trying to accomplish or difficult. " How to back up a Web site to work offline using windows vista?
-
How to change laptop screen between landscape and portrait?
How to change laptop screen between landscape and portrait? I have an ACER ASPIRE 5335 running Windows 7 Pro 32 bit and using the Intel Graphics Media Accelerator driver who pointed out that I use the Chipset Intel 4 Series Express. I tried the thing