Please, help me to query SQL Construct.
Hi Experts,
Could you please help me to query SQL Construct. Please find the details
HOSTNAME HOSTTYPE DEM R1 R2
RS123 P ABC 24.5 265,5
RS123 P CYC 24.5 265,5
RS123 P ADDS 24.5 265,5
RS123 P ADE 24.5 265,5
RS123 P SRC 24.5 265,5
EXPECTED RESULTS
HOSTNAME HOSTTYPE MNE R1 R2
RS123 P ABC, CYC, ADD, ADE, CBC 24.5 265,5
Concerning
See you soon
with t as)
Select "RS123' hostname 'P' hosttype, 'ABC' dem, 24.5 r1, r2 265,5 Union double all the
Select 'RS123', 'P', "CYC", 24.5, 265,5 double Union all
Select 'RS123', 'P', 'ADD', 24.5, 265,5 double Union all
Select "RS123', 'P', 'ADE', 24.5, 265,5 double Union all
Select 'RS123', 'P', 'SRC', 24.5, 265,5 double
)
Select the host name,
HostType,
RTrim (XMLAGG (XmlElement(e,MNE,','). (Extract ('//Text ()')), ',') DEM,.
R1,
R2
t
Group hostname,
HostType,
R1,
R2
/
HOSTN H DEM R1 R2
----- - -------------------- ---------- ----------
RS123 P ABC, CBC, ADE, ADD, CYC 24.5 265,5
SQL >
SY.
Tags: Database
Similar Questions
-
Please help me write this SQL query...
Thanks in advanceHi everyone, Please help me in this query. A patient can multiple types of Adresses (types P,M,D).If they have all the 3 types i need to select type: p and if they have (M and D) i need to select type M,and if they have only type D i have to select that. For each address i need to validate whether that particular address is valid or not (by start date and end date and valid flag) Patient table ============= Patient_id First_name last_name 1 sanjay kumar 2 ajay singh 3 Mike John Adress table ============ address_id patient_id adresss city type startdate enddate valid_flg 1 1 6222 dsadsa P 01/01/2007 01/01/2010 2 1 63333 dsad M 01/02/2006 01/01/2007 N 3 1 64564 fdf M 01/01/2008 07/01/2009 4 1 654757 fsdfsa D 01/02/2008 09/10/2009 5 2 fsdfsd fsdfsd M 01/03/2007 09/10/2009 6 2 jhkjk dsad D 01/01/2007 10/10/2010 7 3 asfd sfds D 01/02/2008 10/10/2009 output ===== 1 sanjay kumar 6222 dsadsa P 01/01/2007 01/01/2010 2 ajay singh fsdfsd fsdfsd M 01/03/2007 09/10/2009 3 mike john asfd sfds D 01/02/2008 10/10/2009
PhaniHello, Fabienne,.
This race for you (twisted code of Sarma):
SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1;
Edit, currently in the trial:
With Patient AS ( SELECT 1 Patient_id , 'sanjay' First_name, 'kumar' last_name FROM DUAL UNION ALL SELECT 2, 'ajay', 'singh' FROM DUAL UNION ALL SELECT 3, 'Mike', 'John' FROM DUAL), Address AS ( SELECT 1 address_id, 1 patient_id, '6222' address, 'dsadsa' city, 'P' type, to_date('01/01/2007', 'DD/MM/YYYY') startdate, to_date('01/01/2010', 'DD/MM/YYYY') enddate, NULL valid_flg FROM DUAL UNION ALL SELECT 2,1,'63333','dsad','M', to_date('01/02/2006', 'DD/MM/YYYY'), to_date('01/01/2007', 'DD/MM/YYYY'), ' N' FROM DUAL UNION ALL SELECT 3,1,'64564','fdf','M', to_date('01/01/2008', 'DD/MM/YYYY'), to_date('07/01/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 4,1,'654757','fsdfsa','D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 5,2,'fsdfsd ','fsdfsd','M', to_date('01/03/2007', 'DD/MM/YYYY'), to_date('09/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 6,2,' jhkjk','dsad','D', to_date('01/01/2007', 'DD/MM/YYYY'), to_date('10/10/2010', 'DD/MM/YYYY'), NULL FROM DUAL UNION ALL SELECT 7,3,'asfd',' sfds',' D', to_date('01/02/2008', 'DD/MM/YYYY'), to_date('10/10/2009', 'DD/MM/YYYY'), NULL FROM DUAL) -- end test data SELECT patient_id, first_name, last_name, address, city, type, startdate, enddate FROM ( SELECT a.patient_id patient_id, first_name, last_name, address, city, type, startdate, enddate, ROW_NUMBER() OVER (PARTITION BY p.patient_id ORDER BY CASE type WHEN 'P' THEN 1 WHEN 'M' THEN 2 WHEN 'D' THEN 3 END) rn FROM patient p JOIN address a ON (p.patient_id = a.patient_id ) WHERE NVL(valid_flg, 'X') != 'N' AND SYSDATE BETWEEN startdate AND NVL(enddate, SYSDATE) ) WHERE rn = 1; PATIENT_ID FIRST_ LAST_ ADDRESS CITY TY STARTDATE ENDDATE ---------- ------ ----- ------- ------ -- --------- --------- 1 sanjay kumar 6222 dsadsa P 01-JAN-07 01-JAN-10 2 ajay singh fsdfsd fsdfsd M 01-MAR-07 09-OCT-09 3 Mike John asfd sfds D 01-FEB-08 10-OCT-09
-
Hello
We have two tables test_a and test_b and would like to get the result of this query:
COL1 VAL_A VAL_B
------------------------------ ------------------------------ -------------
code_1 aa_1 aa_1
code_1 aa_2 aa_2
code_1 aa_3
code_2 bb_1
code_2 bb_2
Could someone please help on this, thanks a lot!
create table test_a)
col1 varchar2 (30),
col2 varchar2 (30));
insert into values test_a ('code_1', 'aa_1');
insert into values test_a ('code_1', 'aa_2');
insert into values test_a ('code_1', 'aa_3');
insert into test_a values ('code_2', 'bb_1');
commit;
create table test_b)
col1 varchar2 (30),
col2 varchar2 (30));
insert into test_b values ('code_1', 'aa_1');
insert into test_b values ('code_1', 'aa_2');
insert into test_b values ('code_2', 'bb_2');
commit;
Select * from test_a;
COL1 COL2
------------------------------ ------------------------------
code_1 aa_1
code_1 aa_2
code_1 aa_3
code_2 bb_1
Select * from test_b;
COL1 COL2
------------------------------ ------------------------------
code_1 aa_1
code_1 aa_2
code_2 bb_2
Published by: user489948 on January 5, 2010 10:13
Published by: user489948 on January 5, 2010 10:15
-
Please help me with this SQL query
I'm practicing of SQL queries and met one involving the extraction of data from 3 different tables.
The three paintings are as below
< pre >
Country
Location_id country
LOC1 Spain
loc2 England
LOC3 Spain
loc4 USA
loc5 Italy
loc6 USA
loc7 USA
< / pre >
< pre >
User
user_id location_id
loc1 U1
loc1 U2
loc2 U3
loc2 U4
loc1 U5
U6 loc3
< / pre >
< pre >
Publish
user_id post_id
P1 u1
P2 u1
U2 P3
P4 u3
P5 u1
P6 u2
< / pre >
I am trying to write a SQL query - for each country of the users, showing the average number of positions
I understand the logic behind all this that we must first consolidate all locations, and then the users in one country and then find the way to their positions.
But, I'm having a difficulty to this format SQL. Could someone help me please with this request.
Thank you.Select
Country.Country,
Count (*) Totalpostspercountry,
Count (distinct post.user_id) Totaldistincuserspercountry,
count (*) / count (distinct post.user_id) Avgpostsperuserbycountry
Of
countries, have, post
where country.location_id = muser.location_id
and muser.user_id = post.user_id
Country.country groupThe output is like this for your sample data - hope that's what you're looking for :)
COUNTRY, TOTALPOSTSPERCOUNTRY, TOTALDISTINCUSERSPERCOUNTRY, AVGPOSTSPERUSERBYCOUNTRY
In England, 1, 1, 1.
Spain, 5, 2, 2.5. -
Please help me fix this SQL query...
Hi, please consider following:
create table test (col varchar2 (255))
insert into test values ("TERM").
Insert test values ("VOLUME");
Select the test pass where pass in ('TIME', 'VOLUME');
This property returns the rows.
but my input string is a comma-separated list:
DURATION, VOLUME
so I try
Select the test pass where col to (replace (' DURATION, VOLUME, ',' "'," '));
but no result. Or:
Select the test pass where col in ("' | replace (' DURATION, VOLUME, ','" ', "') |") ') ;
However
Select "' | Replace (' DURATION, VOLUME, ',' "'," ') | " ' the double
gives "DURATION", "VOLUME".
then why does it work?
hope you can help. Thank youconvert stringlist in lines and then use in the clause...
SELECT col FROM test WHERE col IN (SELECT * FROM (SELECT TRIM( SUBSTR ( txt , INSTR (txt, ',', 1, level ) + 1 , INSTR (txt, ',', 1, level+1 ) - INSTR (txt, ',', 1, level) -1 ) ) AS token FROM ( SELECT ','||'DURATION,VOLUME'||',' AS txt FROM dual ) CONNECT BY level <= LENGTH(txt)-LENGTH(REPLACE(txt,',',''))-1 ) )
Ravi Kumar
-
Please help debug a PL/SQL
Hello
I try to use in bulk collect to change an old PL/SQL (runs, but runs slowly).
-the original
DECLARE
CURSOR C_CURSOR IS SELECT * FROM MF_S224_RPT WHERE UIDY_LO IS NOT NULL AND PATN_LIST IS NOT NULL;
V_DEF_DATA C_CURSOR % ROWTYPE;
str_new_uidy_lo VARCHAR2 (255);
CURSOR C_CURSOR_LN IS SELECT * FROM MF_S224_RPT_LN WHERE UIDY_LO IS NOT NULL;
V_DEF_DATA_LN C_CURSOR_LN % ROWTYPE;
str_new_uidy_lo_ln VARCHAR2 (255);BEGIN
C_CURSOR OPEN;
EXTRACT THE C_CURSOR IN V_DEF_DATA;
C_CURSOR % LOOP WHILE
str_new_uidy_lo: = (' & 6084 &'|) V_DEF_DATA. FISC_YEAR | ' &' | V_DEF_DATA. FISC_MNTH | ' &' | V_DEF_DATA. VR | ' &' | V_DEF_DATA. BENEFITS | ' &' | V_DEF_DATA. PATN_LIST | ' &' | V_DEF_DATA. (SLA);
UPDATE T1 SET T1 MF_S224_RPT. UIDY_LO is str_new_uidy_lo WHERE T1. UIDY_LO = V_DEF_DATA. UIDY_LO;
UPDATE T2 T2 SET MF_S224_RPT_LN. PRPT_ID_LO is str_new_uidy_lo WHERE T2. PRPT_ID_LO = V_DEF_DATA. UIDY_LO;
UPDATE MF_S224_RPT_ACT T5 T5 SET. PRPT_ID_LO is str_new_uidy_lo WHERE T5. PRPT_ID_LO = V_DEF_DATA. UIDY_LO;
EXTRACT THE C_CURSOR IN V_DEF_DATA;
END LOOP;
CLOSE C_CURSOR;
C_CURSOR_LN OPEN;
EXTRACT THE C_CURSOR_LN IN V_DEF_DATA_LN;
C_CURSOR_LN % LOOP WHILE
str_new_uidy_lo_ln: = ('& 6085' |) SUBSTR (V_DEF_DATA_LN. PRPT_ID_LO, 6). ' &' | V_DEF_DATA_LN. TSYM | ' &' | V_DEF_DATA_LN. GLAC | ' &' | V_DEF_DATA_LN. ACMP_YEAR | ' &' | V_DEF_DATA_LN. ACMP_MNTH | ' &' | V_DEF_DATA_LN. RCPT_DISB_IN | ' &' | V_DEF_DATA_LN. PATN);
UPDATE MF_S224_RPT_LN SET T3 T3. UIDY_LO is str_new_uidy_lo_ln WHERE T3. UIDY_LO = V_DEF_DATA_LN. UIDY_LO;
UPDATE MF_S224_RPT_ACT SET T4 T4. PRPT_LINE_ID_LO is str_new_uidy_lo_ln WHERE T4. PRPT_LINE_ID_LO = V_DEF_DATA_LN. UIDY_LO;
EXTRACT THE C_CURSOR_LN IN V_DEF_DATA_LN;
END LOOP;
CLOSE C_CURSOR_LN;
END;
/-Change, to help collect in bulk
DECLARE
CURSOR C_CURSOR IS SELECT * FROM MF_S224_RPT WHERE UIDY_LO IS NOT NULL AND PATN_LIST IS NOT NULL;
TYPE of c_arr1 IS the TABLE OF C_CURSOR % ROWTYPE;
c_rows1 c_arr1;
str_new_uidy_lo VARCHAR2 (500);
CURSOR C_CURSOR_LN IS SELECT * FROM MF_S224_RPT_LN WHERE UIDY_LO IS NOT NULL;
TYPE of c_arr2 IS the TABLE OF C_CURSOR_LN % ROWTYPE;
c_rows2 c_arr2;
str_new_uidy_lo_ln VARCHAR2 (500);
BEGIN
C_CURSOR OPEN;
EXTRACT the C_CURSOR BULK COLLECT INTO c_rows1 LIMIT 2000;
FORALL i IN c_rows1. FIRST... c_rows1. LAST
str_new_uidy_lo: = (' & 6084 &'| c_rows1 (i).) FISC_YEAR | ' &' | c_rows1 (i). FISC_MNTH | ' &' | c_rows1 (i). VR | ' &' | c_rows1 (i). BENEFITS | ' &' | c_rows1 (i). PATN_LIST | ' &' | c_rows1 (i). (SLA);
UPDATE T1 SET T1 MF_S224_RPT. UIDY_LO is str_new_uidy_lo WHERE T1. UIDY_LO = c_rows1 (i). UIDY_LO;
UPDATE T2 T2 SET MF_S224_RPT_LN. PRPT_ID_LO is str_new_uidy_lo WHERE T2. PRPT_ID_LO = c_rows1 (i). UIDY_LO;
UPDATE MF_S224_RPT_ACT T5 T5 SET. PRPT_ID_LO is str_new_uidy_lo WHERE T5. PRPT_ID_LO = c_rows1 (i). UIDY_LO;
WHEN c_rows1 EXIT. COUNTY, 2000;
END LOOP;
CLOSE C_CURSOR;
C_CURSOR_LN OPEN;
EXTRACT the C_CURSOR_LN BULK COLLECT INTO c_rows2 LIMIT 2000;
FORALL i IN c_rows2. FIRST... c_rows2. LAST
str_new_uidy_lo_ln: = ('& 6085' |) SUBSTR (c_rows2 (i). PRPT_ID_LO, 6). ' &' | c_rows2 (i). TSYM | ' &' | c_rows2 (i). GLAC | ' &' | c_rows2 (i). ACMP_YEAR | ' &' | c_rows2 (i). ACMP_MNTH | ' &' | c_rows2 (i). RCPT_DISB_IN | ' &' | c_rows2 (i). PATN);
UPDATE MF_S224_RPT_LN SET T3 T3. UIDY_LO is str_new_uidy_lo_ln WHERE T3. UIDY_LO = c_rows2 (i). UIDY_LO;
UPDATE MF_S224_RPT_ACT SET T4 T4. PRPT_LINE_ID_LO is str_new_uidy_lo_ln WHERE T4. PRPT_LINE_ID_LO = c_rows2 (i). UIDY_LO;
WHEN c_rows2 EXIT. COUNTY, 2000;
END LOOP;
CLOSE C_CURSOR_LN;
END;
/(although, error)
Error report:
ORA-06550: line 18, column 3:
PLS-00103: encountered the symbol "STR_NEW_UIDY_LO" during the expected in the following way:. (* @ % & -+ / to rest rem mod select update with)
< an exponent (*) > remove insert | run save type multiset
Fusion
ORA-06550: line 18, column 172:
PLS-00103: encountered the symbol ";" when expecting one of the following values:), * & = - + <>/ is mod remains not rem
< an exponent (*) > <>or! = or ~ = > = < = <>and like2 or
like4 likec between duplication | multise
ORA-06550: line 24, column 3:
PLS-00103: encountered the symbol "CLOSE" when expecting one of the following conditions:not end up dominant static of final instantiable order pragma
manufacturer membership card
ORA-06550: line 29, column 7:
PLS-00103: encountered the symbol "STR_NEW_UIDY_LO_LN" during the expected in the following way:. (* @ % & -+ / to rest rem mod select update with)
< an exponent (*) > remove insert | run save type multiset
Fusion
ORA-06550: line 29, column 221:
PLS-00103: encountered the symbol ";" when expecting one of the following values:), * & = - + <>/ is mod remains not rem
< an exponent (*) > <>or! = or ~ = > = < = <>and like2 or
like4 likec between duplication | multise
ORA-06550: line 34, column 3:
PLS-00103: encountered the symbol "CLOSE" when expecting one of the following conditions:not end up dominant static of final instantiable order pragma
manufacturer membership card
06550 00000 - "line %s, column % s:\n%s".
* Cause: Usually a PL/SQL compilation error.
* Action:I don't see anything wrong yet... could you help take a look?
Thank you very much!!!
DECLARE CURSOR c_cursor IS SELECT * FROM mf_s224_rpt WHERE uidy_lo IS NOT NULL AND patn_list IS NOT NULL; TYPE c_arr1 IS TABLE OF c_cursor%ROWTYPE; c_rows1 c_arr1; str_new_uidy_lo VARCHAR2(500); CURSOR c_cursor_ln IS SELECT * FROM mf_s224_rpt_ln WHERE uidy_lo IS NOT NULL; TYPE c_arr2 IS TABLE OF c_cursor_ln%ROWTYPE; c_rows2 c_arr2; str_new_uidy_lo_ln VARCHAR2(500); BEGIN OPEN c_cursor; FETCH c_cursor BULK COLLECT INTO c_rows1 LIMIT 2000; FORALL i IN c_rows1.FIRST .. c_rows1.LAST UPDATE mf_s224_rpt t1 SET t1.uidy_lo = str_new_uidy_lo WHERE t1.uidy_lo = c_rows1(i).uidy_lo; UPDATE mf_s224_rpt_ln t2 SET t2.prpt_id_lo = str_new_uidy_lo WHERE t2.prpt_id_lo = c_rows1(i).uidy_lo; UPDATE mf_s224_rpt_act t5 SET t5.prpt_id_lo = str_new_uidy_lo WHERE t5.prpt_id_lo = c_rows1(i).uidy_lo; --EXIT WHEN c_rows1.COUNT < 2000; --END LOOP; str_new_uidy_lo :=('&6084&'||c_rows1(i).fisc_year||'&'||c_rows1(i).fisc_mnth||'&'||c_rows1(i).vrsn||'&'||c_rows1(i).agcy||'&'||c_rows1(i).patn_list||'&'||c_rows1(i).alc); CLOSE c_cursor; OPEN c_cursor_ln; FETCH c_cursor_ln BULK COLLECT INTO c_rows2 LIMIT 2000; FORALL i IN c_rows2.FIRST..c_rows2.LAST UPDATE mf_s224_rpt_ln t3 SET t3.uidy_lo = str_new_uidy_lo_ln WHERE t3.uidy_lo = c_rows2(i).uidy_lo; UPDATE mf_s224_rpt_act t4 SET t4.prpt_line_id_lo = str_new_uidy_lo_ln WHERE t4.prpt_line_id_lo = c_rows2(i).uidy_lo; --EXIT WHEN c_rows2.COUNT < 2000; --END LOOP; str_new_uidy_lo_ln :=('&6085'||SUBSTR(c_rows2(i).prpt_id_lo, 6)||'&'||c_rows2(i).tsym||'&'||c_rows2(i).glac||'&'||c_rows2(i).acmp_year||'&'||c_rows2(i).acmp_mnth||'&'||c_rows2(i).rcpt_disb_in||'&'||c_rows2(i).patn); CLOSE c_cursor_ln; END;
A FORALL statement submit your statement number 'x' DML time all of a sudden. Why do you 2 UPDATE instructions, I'm not sure. But also your assignment to a string variable cannot be fair after the FORALL as it is NOT a loop.
-
Please help with parallel query
Hi all
I am "playing" with a parallel query and try to see if it could improve some more long running queries, but can't do the database that you want to use a parallel execution plan, no matter what I do! I hope someone can point me in the right direction!
ORACLE Version is 11.2.0.2
OS Win 2008 R2 server
UC = 32
64 GB OF RAM
AMM enabled, memory_target = M 50560
SQL > show the parallel parameter
I also ran the calibration of IO which resultet
VALUE OF TYPE NAME
------------------------------------ ----------- --------------
fast_start_parallel_rollback string LOW
parallel_adaptive_multi_user Boolean TRUE
parallel_automatic_tuning boolean FALSE
parallel_degree_limit string CPU
parallel_degree_policy string AUTO
parallel_execution_message_size integer 16384
parallel_force_local boolean FALSE
parallel_instance_group string
parallel_io_cap_enabled boolean FALSE
PARALLEL_MAX_SERVERS integer 985
parallel_min_percent integer 0
VALUE OF TYPE NAME
------------------------------------ ----------- --------------
parallel_min_servers integer 16
parallel_min_time_threshold channel 5
parallel_server boolean FALSE
parallel_server_instances integer 1
parallel_servers_target integer 512
parallel_threads_per_cpu integer 2
recovery_parallelism integer 0
Max e/s per second 21569
I collected statistics of the system, the 1 hour time. the results are:
Max Mo / second 989
Select pname, sys.aux_stats pval1 $;
I changed all my tables and indexes using 'ALTER TABLE xxx PARALLEL' then when I query the dba_tables, the DEGREE is DEFAULT for all objects invoked in my queries.
STATUS
DSTART
DSTOP
FLAGS 0
CPUSPEEDNW 915
IOSEEKTIM 10
IOTFRSPEED 4096
SREADTIM 0.589
MREADTIM 0.841
CPUSPEED 1355
MBRC 11
MAXTHR 679936
SLAVETHR
what I've learned so far, I put all the necessary parameters.
From my understanding, all queries who believe more than 5 seconds, should be tried to run in parallel (parallel_min_time_threshold = 5). But not a single query is doing at least this forced manually with a / * + PARALLEL * / tip! It drives me crazy. Choose manually a degree of 16 for example allows to speed up some queries from 15 minutes to 1 minute, but why ORACLE does not by itself?
Given that it is a Siebel application, that we are talking about, there is no possibility of adding tips for SQL.
example:
This query took 29 seconds to complete, but was executed in SERIES
SQL_ID, atzj0dmhshb23, number of children 0
-------------------------------------
SELECT T7. CONFLICT_ID, T7. LAST_UPD, T7. CREATED,
T7. LAST_UPD_BY, T7. CREATED_BY, T7. MODIFICATION_NUM,
T7. ROW_ID, T9. MAIN_PH_NUM, T9.NAME, T9. REGION,
T9. X_SUB_REGION, T20. ATTRIB_44, T20. ATTRIB_26,
T20. ATTRIB_45, T20. ATTRIB_27, T20. ATTRIB_03,
T33. SUPPRESS_MAIL_FLG, T33. EMAIL_ADDR, T33. MID_NAME,
T33. PR_DEPT_OU_ID, T33. LAST_NAME, T33. SEX_MF,
T33. PR_PER_ADDR_ID, T33. PR_POSTN_ID, T30. PR_ADDR_ID,
T33. HOME_PH_NUM, T33. OWNER_PER_ID, T33. WORK_PH_NUM,
T33. FAX_PH_NUM, T33. FST_NAME, T20. ATTRIB_07,
T3. INTEGRATION_ID, T33. PR_PER_PAY_PRFL_ID, T33. PRIV_FLG,
T33. PR_MKT_SEG_ID, T33. PR_REP_SYS_FLG,
T33. PR_REP_MANL_FLG, T33. PR_REP_DNRM_FLG, T33. PR_OPTY_ID,
T33. PR_GRP_OU_ID, T33. EMP_FLG, T8. OWN_INST_ID,
T8. INTEGRATION_ID, T33. PERSON_UID, T7. NAM
Hash value of plan: 35208051
---------------------------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
---------------------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | 34 (100) |
| 1. NESTED EXTERNAL LOOPS | 10. 42440 | 34 (0) | 00:00:01 |
| 2. NESTED EXTERNAL LOOPS | 10. 42300 | 33 (0) | 00:00:01 |
| 3. NESTED EXTERNAL LOOPS | 10. 42160 | 32 (0) | 00:00:01 |
| 4. NESTED EXTERNAL LOOPS | 10. 42020 | 31 (0) | 00:00:01 |
| 5. NESTED LOOPS | 10. 41880 | 30 (0) | 00:00:01 |
| 6. NESTED EXTERNAL LOOPS | 11. 45947 | 29 (0) | 00:00:01 |
| 7. NESTED LOOPS | 11. 45716 | 28 (0) | 00:00:01 |
| 8. NESTED EXTERNAL LOOPS | 11. 45364 | 27 (0) | 00:00:01 |
| 9. NESTED EXTERNAL LOOPS | 11. 45243 | 26 (0) | 00:00:01 |
| 10. NESTED EXTERNAL LOOPS | 11. 45122 | 25 (0) | 00:00:01 |
| 11. NESTED EXTERNAL LOOPS | 11. 43648 | 24 (0) | 00:00:01 |
| 12. NESTED EXTERNAL LOOPS | 11. 37070 | 23 (0) | 00:00:01 |
| 13. NESTED EXTERNAL LOOPS | 11. 34661 | 22 (0) | 00:00:01 |
| 14. NESTED EXTERNAL LOOPS | 11. 34430 | 21 (0) | 00:00:01 |
| 15. NESTED EXTERNAL LOOPS | 11. 33891 | 20 (0) | 00:00:01 |
| 16. NESTED EXTERNAL LOOPS | 11. 33253 | 19 (0) | 00:00:01 |
| 17. NESTED EXTERNAL LOOPS | 11. 32362 | 18 (0) | 00:00:01 |
| 18. NESTED EXTERNAL LOOPS | 11. 31999 | 17 (0) | 00:00:01 |
| 19. NESTED EXTERNAL LOOPS | 11. 29337 | 16 (0) | 00:00:01 |
| 20. NESTED EXTERNAL LOOPS | 11. 28556 | 15 (0) | 00:00:01 |
| 21. NESTED EXTERNAL LOOPS | 11. 28061 | 14 (0) | 00:00:01 |
| 22. NESTED EXTERNAL LOOPS | 11. 26400 | 13 (0) | 00:00:01 |
| 23. NESTED EXTERNAL LOOPS | 11. 26169 | 12 (0) | 00:00:01 |
| 24. NESTED EXTERNAL LOOPS | 11. 25465 | 10 (0) | 00:00:01 |
| 25. NESTED EXTERNAL LOOPS | 11. 21131. 9 (0) | 00:00:01 |
| 26. NESTED EXTERNAL LOOPS | 11. 18326. 8 (0) | 00:00:01 |
| 27. NESTED LOOPS | 11. 13651 | 7 (0) | 00:00:01 |
| 28. NESTED EXTERNAL LOOPS | 11. 12452. 6 (0). 00:00:01 |
| 29. NESTED EXTERNAL LOOPS | 11. 10978. 5 (0) | 00:00:01 |
| 30. NESTED LOOPS | 11. 9504. 4 (0) | 00:00:01 |
| 31. NESTED EXTERNAL LOOPS | 4. 360 | 3 (0) | 00:00:01 |
| 32. NESTED LOOPS | 4. 228. 2 (0) | 00:00:01 |
| * 33 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1. 11. 1 (0) | 00:00:01 |
| 34. TABLE ACCESS BY INDEX ROWID | S_CONTACT_BU | 4. 184. 1 (0) | 00:00:01 |
| * 35 | INDEX RANGE SCAN | S_CONTACT_BU_M1 | 4 | | 1 (0) | 00:00:01 |
| 36. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 33. 1 (0) | 00:00:01 |
| * 37 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| * 38 | TABLE ACCESS BY INDEX ROWID | S_CONTACT. 3. 2322 | 1 (0) | 00:00:01 |
| * 39 | INDEX UNIQUE SCAN | S_CONTACT_P1 | 1 | | 1 (0) | 00:00:01 |
| 40. TABLE ACCESS BY INDEX ROWID | S_MED_SPEC | 1. 134. 1 (0) | 00:00:01 |
| * 41. INDEX UNIQUE SCAN | S_MED_SPEC_P1 | 1 | | 1 (0) | 00:00:01 |
| 42. TABLE ACCESS BY INDEX ROWID | S_PRI_LST | 1. 134. 1 (0) | 00:00:01 |
| * 43. INDEX UNIQUE SCAN | S_PRI_LST_P1 | 1 | | 1 (0) | 00:00:01 |
| * 44 | TABLE ACCESS BY INDEX ROWID | S_PARTY | 1. 109. 1 (0) | 00:00:01 |
| * 45 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1 | | 1 (0) | 00:00:01 |
| 46. TABLE ACCESS BY INDEX ROWID | S_CONTACT_SS | 1. 425. 1 (0) | 00:00:01 |
| * 47 | INDEX RANGE SCAN | S_CONTACT_SS_U1 | 1 | | 1 (0) | 00:00:01 |
| 48. TABLE ACCESS BY INDEX ROWID | S_CONTACT_LOYX | 1. 255. 1 (0) | 00:00:01 |
| * 49 | INDEX RANGE SCAN | S_CONTACT_LOYX_U1 | 1 | | 1 (0) | 00:00:01 |
| * 50 | INDEX RANGE SCAN | S_DQ_CON_KEY_U1 | 1. 394. 1 (0) | 00:00:01 |
| * 51 | TABLE ACCESS FULL | S_CASE | 1. 64. 0 (0) |
| 52. TABLE ACCESS BY INDEX ROWID | S_POSTN | 1. 21. 1 (0) | 00:00:01 |
| * 53 | INDEX UNIQUE SCAN | S_POSTN_U2 | 1 | | 1 (0) | 00:00:01 |
| 54. TABLE ACCESS BY INDEX ROWID | S_EMP_PER | 1. 151. 1 (0) | 00:00:01 |
| * 55 | INDEX UNIQUE SCAN | S_EMP_PER_U1 | 1 | | 1 (0) | 00:00:01 |
| 56. TABLE ACCESS BY INDEX ROWID | S_POSTN_CON | 1. 45. 1 (0) | 00:00:01 |
| * 57 | INDEX RANGE SCAN | S_POSTN_CON_M3 | 4 | | 1 (0) | 00:00:01 |
| 58. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_FNX | 1. 71. 1 (0) | 00:00:01 |
| * 59 | INDEX RANGE SCAN | S_ORG_EXT_FNX_U1 | 1 | | 1 (0) | 00:00:01 |
| 60. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_X | 1. 242. 1 (0) | 00:00:01 |
| * 61. INDEX RANGE SCAN | S_ORG_EXT_X_U1 | 1 | | 1 (0) | 00:00:01 |
| 62. TABLE ACCESS BY INDEX ROWID | S_CON_ADDR | 1. 33. 1 (0) | 00:00:01 |
| * 63. INDEX RANGE SCAN | S_CON_ADDR_M51 | 1 | | 1 (0) | 00:00:01 |
| 64. TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1. 51 M | 1 (0) | 00:00:01 |
| * 65 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0) | 00:00:01 |
| 66. TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1. 58. 1 (0) | 00:00:01 |
| * 67. INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0) | 00:00:01 |
| 68. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 49. 1 (0) | 00:00:01 |
| * 69 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| 70. TABLE ACCESS BY INDEX ROWID | S_POSTN | 1. 21. 1 (0) | 00:00:01 |
| * 71 | INDEX UNIQUE SCAN | S_POSTN_U2 | 1 | | 1 (0) | 00:00:01 |
| 72. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 219. 1 (0) | 00:00:01 |
| * 73 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| 74. TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1. 598. 1 (0) | 00:00:01 |
| * 75 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0) | 00:00:01 |
| 76. TABLE ACCESS BY INDEX ROWID | S_CONTACT_X | 1. 134. 1 (0) | 00:00:01 |
| * 77 | INDEX RANGE SCAN | S_CONTACT_X_U1 | 1 | | 1 (0) | 00:00:01 |
| * 78 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1. 11. 1 (0) | 00:00:01 |
| * 79 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1. 11. 1 (0) | 00:00:01 |
| 50 M | TABLE ACCESS BY INDEX ROWID | S_POSTN_CON | 1. 32. 1 (0) | 00:00:01 |
| * 81 | INDEX RANGE SCAN | S_POSTN_CON_M3 | 1 | | 1 (0) | 00:00:01 |
| 82. TABLE ACCESS BY INDEX ROWID | S_POSTN | 1. 21. 1 (0) | 00:00:01 |
| * 83 | INDEX UNIQUE SCAN | S_POSTN_U2 | 1 | | 1 (0) | 00:00:01 |
| * 84 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1. 11. 1 (0) | 00:00:01 |
| 85. TABLE ACCESS BY INDEX ROWID | S_USER | 1. 14. 1 (0) | 00:00:01 |
| * 86 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0) | 00:00:01 |
| 87. TABLE ACCESS BY INDEX ROWID | S_USER | 1. 14. 1 (0) | 00:00:01 |
| * 88. INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0) | 00:00:01 |
| 89. TABLE ACCESS BY INDEX ROWID | S_USER | 1. 14. 1 (0) | 00:00:01 |
| * 90 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0) | 00:00:01 |
| 91. TABLE ACCESS BY INDEX ROWID | S_USER | 1. 14. 1 (0) | 00:00:01 |
| * 92 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0) | 00:00:01 |
---------------------------------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
33 - access("T15".") ROW_ID "(=:2)"
35 - access("T1".") BU_ID "(=:2)"
37 - access("T2".") PAR_ROW_ID "(=:2)"
38 - filter ((NLS_UPPER ("LAST_NAME", '= "GENERIC_BASELETTER" nls_sort') AS
NLS_UPPER(:3,'nls_sort=''GENERIC_BASELETTER''') AND 'T33 '. "PRIV_FLG"(='N')) "
39 - access("T33".") ROW_ID '= 'T1'.' CONTACT_ID')
41 - access("T33".") MED_SPEC_ID '= 'T5'.' ROW_ID")
43 - access("T33".") CURR_PRI_LST_ID "="T18"." ROW_ID")
44 - filter("T7".") PARTY_TYPE_CD' <>'Suspect')
45 - access("T7".") ROW_ID "= 'T33'." PAR_ROW_ID')
47 - access("T7".") ROW_ID "="T8"." PAR_ROW_ID')
49 - access("T7".") ROW_ID "="T12"." PAR_ROW_ID')
50 - access("T7".") ROW_ID "="T19"." CONTACT_ID')
51 - filter("T7".") ROW_ID "= 'T25'." PR_SUBJECT_ID')
53 - access("T33".") PR_POSTN_ID "="T21"." PAR_ROW_ID')
55 - access("T7".") ROW_ID "="T23"." PAR_ROW_ID')
57 - access("T30".") POSTN_ID ' =: 1 AND "T7".» ROW_ID "= 'T30'." CON_ID')
59 - access("T33".") PR_DEPT_OU_ID '= 'T22'.' PAR_ROW_ID')
61 - access("T33".") PR_DEPT_OU_ID "="T14"." PAR_ROW_ID')
63 - access("T33".") PR_OU_ADDR_ID '= 'T11'.' ADDR_PER_ID' AND 'T33 '. "PR_DEPT_OU_ID"= "T11". ("' ACCNT_ID")
65 - access("T33".") PR_PER_ADDR_ID "="T32"." ROW_ID")
67 - access("T33".") PR_OU_ADDR_ID "="T17"." ROW_ID")
69 - access("T33".") PR_DEPT_OU_ID '= 'T3'.' PAR_ROW_ID')
71 - access("T3".") PR_POSTN_ID '= 'T31'.' PAR_ROW_ID')
73 - access("T33".") PR_DEPT_OU_ID "="T9"." PAR_ROW_ID')
75 - access("T33".") PR_DEPT_OU_ID '= 'T13'.' PAR_ROW_ID')
77 - access("T7".") ROW_ID "="T20"." PAR_ROW_ID')
78 - access("T33".") PR_DEPT_OU_ID '= 'T4'.' ROW_ID")
79 - access("T33".") PR_SYNC_USER_ID '= 'T16'.' ROW_ID")
81 - access("T33".") PR_POSTN_ID '= 'T29'.' POSTN_ID' AND 'T33 '. "ROW_ID"= 'T29'. ("' CON_ID")
83 - access("T29".") POSTN_ID "="T6"." PAR_ROW_ID')
84 - access("T29".") POSTN_ID "= 'T27'." ROW_ID")
86 - access("T6".") PR_EMP_ID "="T26"." PAR_ROW_ID')
88 - access("T21".") PR_EMP_ID '= 'T28'.' PAR_ROW_ID')
90 - access("T31".") PR_EMP_ID '= 'T24'.' PAR_ROW_ID')
92 - access("T33".") PR_SYNC_USER_ID '= 'T10'.' PAR_ROW_ID')
Note
-----
-dynamic sample used for this survey (level = 5)
-Automatic DOP: calculated degree of parallelism is 1 because of the parallel threshold
-Profile SQL SYS_SQLPROF_013b617a8f0b005f used for this statement
Looks like ORACLE considers all my questions with '1 second' which is the parallel threshold (5 seconds) and so works in series? Or am I completely wrong?
(continued)
Edited by: Penky 5 December 2012 09:37Penky wrote:
Randolf,db_file_multiblock_read_count find not at all as far as I know, so it translates the default of 128 to 11 g. I read somewhere that it's not recommended to set it manually 10 or 11 and following.
Thank you for the values. Which is recommended, fix, but still a lot together sites of value to something by default. I don't know yet where this MB_IO_COUNT = 8 comes, however.
Furthermore, if you do want to play with the DOP Auto, you could just stick to the old manual DOP. If you set your PARALLEL_DEGREE_POLICY MANUAL, but have the objects marked as PARALLEL, you should get a PARALLEL query, it has provided is no less available to the optimizer serial plan.
The default DOP is very susceptible to high (64 per node with your given configuration), you can set the PARALLEL degree to something lower.
You could also play with ALTER SESSION FORCE PARALLEL QUERY PARALLEL x if you want / can limit this to specific sessions, then you have even to mark objects as PARALLEL, such that it could have side effects to other processes that you do not want to run in parallel.
Randolf
-
Please help improve the query with the analytic function
The mentioned below query takes about 10 hours to complete (10.2.0.4).
There are 3 tables (table t has a relationship 1: n with table e and k table also has a relationship 1: n with table e).
Table a contains 200,000 lines. (this table is truncated and inserted several times a week)
E table contains rows of 1Mio.
K table contains rows of 170Mio.
I need a query that takes the latest 3 posts for a given t_id:drop table t; create table t ( t_id number, constraint t_pk primary key (t_id) ); drop table e; create table e ( e_id number, e_doc nvarchar2(16), e_date date, constraint e_pk primary key (e_id) ); drop table k; create table k ( t_id number, e_id number ); create unique index k_i1 on k(t_id, e_id); exec dbms_stats.gather_table_stats(user, 'T'); exec dbms_stats.gather_table_stats(user, 'K'); exec dbms_stats.gather_table_stats(user, 'E'); -- Sample data: insert into t(t_id) values (100); insert into t(t_id) values (101); insert into t(t_id) values (102); insert into t(t_id) values (103); insert into e(e_id, e_doc, e_date) values (200, 'doc 200', to_date('01.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (201, 'doc 201', to_date('02.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (202, 'doc 202', to_date('03.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (203, 'doc 203', to_date('04.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (204, 'doc 204', to_date('05.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (205, 'doc 205', to_date('06.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (206, 'doc 206', to_date('07.01.2010', 'DD.MM.YYYY')); insert into e(e_id, e_doc, e_date) values (207, 'doc 207', to_date('08.01.2010', 'DD.MM.YYYY')); insert into k(t_id, e_id) values (100, 200); insert into k(t_id, e_id) values (100, 201); insert into k(t_id, e_id) values (100, 202); insert into k(t_id, e_id) values (100, 203); insert into k(t_id, e_id) values (101, 203); insert into k(t_id, e_id) values (101, 204); select k.t_id, e.e_date, e.e_id, e.e_doc from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc; T_ID E_DATE E_ID E_DOC ---------- -------- ---------- ---------------- 100 04.01.10 203 doc 203 100 03.01.10 202 doc 202 100 02.01.10 201 doc 201 100 01.01.10 200 doc 200 101 05.01.10 204 doc 204 101 04.01.10 203 doc 203
The example query takes several hours in production.T_ID E_DOC_LIST ---------- ----------------------- 100 doc 200/doc 201/doc 202 101 doc 203/doc 204 Sample query: select t_id, e_doc_list from ( select k.t_id, row_number() over(partition by k.t_id order by k.t_id, e.e_date desc) r_num, rtrim( lag(e.e_doc, 0) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 1) over(partition by k.t_id order by k.t_id, e.e_date) || '/' || lag(e.e_doc, 2) over(partition by k.t_id order by k.t_id, e.e_date), '/') e_doc_list from e, k, t where k.e_id = e.e_id and k.t_id = t.t_id order by k.t_id, e.e_date desc ) where r_num = 1 ; T_ID E_DOC_LIST ---------- -------------------------------------------------- 100 doc 203/doc 202/doc 201 101 doc 204/doc 203
The r_num = 1 filter is applied quite late. Is there another way to generate the query or even review the tables.
For the sample query: ----------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 6 | 468 | 6 (50)| 00:00:01 | |* 1 | VIEW | | 6 | 468 | 6 (50)| 00:00:01 | |* 2 | WINDOW SORT PUSHED RANK | | 6 | 216 | 6 (50)| 00:00:01 | | 3 | WINDOW SORT | | 6 | 216 | 6 (50)| 00:00:01 | | 4 | NESTED LOOPS | | 6 | 216 | 4 (25)| 00:00:01 | | 5 | MERGE JOIN | | 6 | 198 | 4 (25)| 00:00:01 | | 6 | TABLE ACCESS BY INDEX ROWID| E | 8 | 208 | 2 (0)| 00:00:01 | | 7 | INDEX FULL SCAN | E_PK | 8 | | 1 (0)| 00:00:01 | |* 8 | SORT JOIN | | 6 | 42 | 2 (50)| 00:00:01 | | 9 | INDEX FULL SCAN | K_I1 | 6 | 42 | 1 (0)| 00:00:01 | |* 10 | INDEX UNIQUE SCAN | T_PK | 1 | 3 | 0 (0)| 00:00:01 | ----------------------------------------------------------------------------------------- Predicate Information (identified by operation id): --------------------------------------------------- 1 - filter("R_NUM"=1) 2 - filter(ROW_NUMBER() OVER ( PARTITION BY "K"."T_ID" ORDER BY "K"."T_ID",INTERNAL_FUNCTION("E"."E_DATE") DESC )<=1) 8 - access("K"."E_ID"="E"."E_ID") filter("K"."E_ID"="E"."E_ID") 10 - access("K"."T_ID"="T"."T_ID") and for query in production --------------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| --------------------------------------------------------------------------------------- | 0 | SELECT STATEMENT | | 3118K| 425M| | 160K (1)| | 1 | VIEW | | 3118K| 425M| | 160K (1)| | 2 | SORT ORDER BY | | 3118K| 163M| 383M| 160K (1)| | 3 | WINDOW SORT PUSHED RANK| | 3118K| 163M| 383M| 160K (1)| | 4 | WINDOW SORT | | 3118K| 163M| 383M| 160K (1)| | 5 | HASH JOIN | | 3118K| 163M| 40M| 33991 (1)| | 6 | TABLE ACCESS FULL | E | 1053K| 28M| | 4244 (1)| | 7 | NESTED LOOPS | | 3118K| 80M| | 21918 (1)| | 8 | TABLE ACCESS FULL | T | 144K| 1829K| | 282 (2)| | 9 | INDEX RANGE SCAN | K_I1 | 22 | 308 | | 1 (0)| ---------------------------------------------------------------------------------------
TimWong765 wrote:
...
Table a contains 200,000 lines. (* this table is truncated and inserted several times a week *)You could be in one of the rare cases where the index should be rebuild, take a look in the following thread:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:6601312252730 #69571308712887 (search for 'index of Sweeper')
Make sure that you have checked if you are in this case before going for an expensive index rebuild.Nicolas.
-
Hi Please help me write a sql query to convert data from the source table to the destination table, as shown in the example given below.
Destination table for the source table
CRAZY ACCT DATA CRAZY D1 D2
11000 007 AA AA A11 11000
11000 013 BB B11 11001 A11
11001 11002 C11 BB CC 007
11001 013 B11
11002 007 CC
11002 013 C11
RDS,
Nagainsert into dest_table select s1.fou, s1.data, s2.data from src_table s1 ,src_table s2 where s1.fou = s2.fou and s1.act = '007' and s2.act = '013'
No warranty with regard to performance... (could be bad if src_table is huge).
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
query SQL related beaking the string based on the position of the string
Hello
I've got coloumn in this way
city_state
----------------
Texas tx
sanantanio tx
New York ny
nj newjersy
NewYork
newjersy
Landon 1000
I want to get the last characters after the string space (for example: texas tx) tx only, which means that I want only to break the chains that have space in 3rd place during the counting of the chain from the rear. other records that do not match as above indicated should decoded as "unknown".
(for example 'landon 1000' decode as unknown or "New York" decodes Unknown)
can someone please help with this query.
Thank you
RAMHi, Ram,
You can use SUBSTR to get the antepenultimate character (in other words, the 3rd from the end: I don't get to use that Word every day) and the last 2 characters.
If the 2nd argument SUBSTR is a negative number, this means the end count.
For example:SELECT city_state , CASE WHEN SUBSTR (city_state, -3, 1) = ' ' THEN SUBSTR (city_state, -2) ELSE 'Unknown' END AS state FROM table_x ;
-
I have some problem in my query to sql server. If I press f5 to run it opens to record dialogue area nd do not run (I don't get successful... orders etc). Please help me
Hello
SQL Server is not supported in these forums. I suggest that you ask your question again in one of the forums dedicated to Microsoft for him here:
http://social.technet.microsoft.com/Forums/en-us/category/sqlserver .
Thank you. :)
-
Hello
Please help build a sql query
My Table Test2015 has given belowHeader_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887292 SH-POS-NO-BR POS-INS
199926 723887293 MAIN2
199927 723887294 IC-ENV-NON-BR-ENV-PXY
199927 723887295 MAIN1
199927 723887297 MAIN2
199927 723887298 PRCSS SH-FAIRY-ELEC DISTR.
199927 723887299 SH-FAIRY-SUM PRO-DE-CONS-HOUSE
I am trying to query my Test2015 table to obtain the records with ordered_item containing 'MAIN1' and 'MAIN2' only. I tried to write a query as below
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1', 'MAIN2');
But it gives me all the data with the MAIN2 records found but MAIN1 is absent, I want to retrieve only records to both 'MAIN1' and 'MAIN2' present for Header_id.
While the result below shows me header_id - 199926 and 199929 that he should assume back. I want to fetch documents only with 'MAIN1' and 'MAIN2' both present.
Header_id Line_id Ordered_item
723887290 199925 MAIN1
199925 723887291 MAIN2
199926 723887293 MAIN2
199927 723887295 MAIN1
199927 723887297 MAIN2
199929 723887299 MAIN1
Please suggest.
Thank you and best regards,
Prasad.
Hello
Try like this...
SELECT * FROM test2015 WHERE ORDERED_ITEM in ('MAIN1") and in header_id (select test2015 WHERE ORDERED_ITEM in ('MAIN2') header_id)
-
My requirement is to calculate a few things like total_cash_amount, TOTAL_CO_PATIENT_AMOUNT etc... For this we will use BILLING. PATIENTBILL, BILLING. PATIENTBILLDETAILS, BILLING. Operating tables. Here it is already developed procedure.
I'm askd to change the same for best performance. This is the part of it that is calculation of total_cash_amount. There will be two categories such as INPATIENT (IP) and OUTPATIENT (OP). Can anyone of you please help me to change the code in a manner better. And can you please suggest that global temporary tables are better or can we use the tables directly.
Thanks in advance...INSERT INTO GTT_PATIENTBILL SELECT * FROM BILLING.PATIENTBILL P WHERE P.LOCATIONID = IN_LOCATIONID AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE); INSERT INTO GTT_PATIENTBILLDETAILS SELECT PB.* FROM BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID AND P.BILLNO = PB.BILLNO AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE); INSERT INTO GTT_TRANSACTION SELECT * FROM BILLING.TRANSACTION T WHERE T.LOCATIONID = IN_LOCATIONID AND TRUNC(T.CREATEDDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE); DELETE FROM TEMP_1; INSERT INTO TEMP_1 SELECT (CASE WHEN PARTICULARS IS NULL AND FLG = 1 THEN 'TOTAL COLLECTIONS' WHEN PARTICULARS IS NULL AND FLG = 2 THEN 'TOTAL DEDUCTIONS' ELSE PARTICULARS END) PARTICULARS, SUM(A) "FOR THE DAY", SUM(B) "MONTH TO DATE", SUM(C) "YEAR TO DATE" FROM (SELECT PARTICULARS, SUM(TOTAL_CASH_AMOUNT_DAY) A, SUM(TOTAL_CASH_AMOUNT_MONTH) B, SUM(TOTAL_CASH_AMOUNT_YEAR) C, 1 FLG FROM (SELECT 'OP CASH' PARTICULARS, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_DAY, 0 TOTAL_CASH_AMOUNT_MONTH, 0 TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 2 AND TRUNC(P.BILLDATE) =TRUNC(IN_FROMDATE) UNION ALL SELECT 'OP CASH' PARTICULARS, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_MONTH, 0 FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 2 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_MONTHDATE) AND TRUNC(IN_FROMDATE) UNION ALL SELECT 'OP CASH' PARTICULARS, 0, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 2 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE) UNION ALL SELECT 'IP CASH' PARTICULARS, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_DAY, 0 TOTAL_CASH_AMOUNT_MONTH, 0 TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 3 AND TRUNC(P.BILLDATE) = TRUNC(IN_FROMDATE) UNION ALL SELECT 'IP CASH' PARTICULARS, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_MONTH, 0 FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 3 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_MONTHDATE) AND TRUNC(IN_FROMDATE) UNION ALL SELECT 'IP CASH' PARTICULARS, 0, 0, SUM(P.TOTALSERVICEAMOUNT) TOTAL_CASH_AMOUNT_YEAR FROM GTT_PATIENTBILL P--BILLING.PATIENTBILL P, BILLING.PATIENTBILLDETAILS PB WHERE P.LOCATIONID = IN_LOCATIONID --AND P.BILLNO = PB.BILLNO AND P.BILLINGTYPEID = 1 AND P.PATIENTSERVICE = 3 AND TRUNC(P.BILLDATE) BETWEEN TRUNC(IN_YEARDATE) AND TRUNC(IN_FROMDATE)) T1 GROUP BY PARTICULARS
You can do this in the same query. As long as the underlying table is the same thing that you don't have to have multiple queries to the same table. You just improvise on your selection fields. Use a CASE statement instead of DECIDING that I used and include the other INDICATIONS which I didn't understand.
-
Please help me find the solution for the query
Hi Experts,
Please help build a sql query. Thank you
Examples of data
-------------------
create the table Material_tb
(
Detail varchar2 (20).
Description varchar2 (200)
)
/
Start
Insert into material_tb values('Color','Red,Blue,Black,Green,White');
Insert into material_tb values ('Material','Gold, Silver, Platinum');
end;
/
Select * from material_tb;
DETAIL DESCRIPTION
-------------------- ------------------------------
Color red, blue, black, green, white
Material gold, silver, Platinum
I want that output voltage
DETAIL DESCRIPTION
-------------------- ------------------------------
Red color
Blue color
Black color
Green color
White color
Material gold
Silver material
Platinum material
You can try under sql
select distinct detail,regexp_substr(description,'[^,]+',1,LEVEL) from material_tb connect by regexp_substr(description,'[^,]+',1,LEVEL) is not null order by 1
Maybe you are looking for
-
record online audio on the iMac 27-inch with screen Retina 5 K?
How can I record a quality online on my iMac 27-inch with screen Retina 5 K? Any suggestions?
-
Cannot delete 'alert warning' in the Safari iPad iOS 9.3.1 Air app
I have a 'alert warning to the Virus' that I can't delete my Safari app. It seems to hang out in the list at the bottom of the cross-tab screen which we can access by clicking the several page icon at the top right of the Safari icon window. I tried
-
PAVILION DV6 - 1128TX: System disabled screen
Hey I just got bougjt this HP of Kijiji and ive turned on and its come up with system disbled it please help as soon as POSSIBLE please
-
Problem with the release of DAQmx not adjusted
Hello I'm trying to convert a recording program generally written in Labview to exit of the floating numbers of unsigned integers. I use the DAQmx read where I choose the unadjusted output (2D U16 NChan), the Board of Directors is a PCI-6023E. I have
-
Foires config pages (WRT160N)
I had a problem with the speed of the internet on one of my computers, then I tried a firmwareupdate since version 2.0.0.1 for 2.0.0.2 and upgrade page stopped after a while. I thought it was an auto reset of the router, but internet has always worke