Need to write a query
Hi Master,
SELECT A.MESSAGE_TYPE,
A.SENDER_ID, B.LICENSE_TYPE,
B.CUST_SALES_ORDER_NO,
B.BUID,
B.WORK_ORDER_NO,
B.SERVICE_TAG,
B.PRODUCT_KEY_SERIAL_NUMBER,
B.REF_ID,
B.HARDWARE_HASH,
B.ERROR_CODE,
C.ERROR_DESCRIPTION,
D.WARNING_CODE,
A.CREATED_BY,
A.CREATION_DATE
OF LK_MD_MESSAGE_STAGING,.
B LK_MD_MESSAGE_UNIT_STAGING,
LK_MM_OEM_ERROR_CODE C.
LK_MD_MESSAGE_UNIT_WARNING D
WHERE A.MESSAGE_STAGING_ID = B.MESSAGE_STAGING_ID
AND B.ERROR_CODE = C.ERROR_CODE - need to left outer join
AND B.MESSAGE_UNIT_ID = D.MESSAGE_UNIT_ID - need to left outer join.
Please help me
Concerning
AR
Can be
select a.message_type , a.sender_id , b.license_type , b.cust_sales_order_no , b.buid , b.work_order_no , b.service_tag , b.product_key_serial_number , b.ref_id , b.hardware_hash , b.error_code , c.error_description , d.warning_code , a.created_by , a.creation_date from lk_md_message_staging a join lk_md_message_unit_staging b on a.message_staging_id = b.message_staging_id left join lk_mm_oem_error_code c on b.error_code = c.error_code left join lk_md_message_unit_warning d on b.message_unit_id = d.message_unit_id;
Tags: Database
Similar Questions
-
Need to write a query that takes more than 2 minutes to run
Hello
I use Oracle 10 g in my database.
I am writing a small program for test purposes, my requirement is to write a query that takes more than 2 minutes to run. Right now I have only a small Table, called 'Users' with very less data.
Please let me know how I can get this thing?
Thank you.How to make a request for execution for more than 2 minutes with basic data.
as below
Select * from $ source, $or any generic query of CARTESIAN PRODUCT
-
How to write conditional query?
I have a use case-
on the basis of the value of the entry, I need to run the query.
for example
Select * from employees where em em. empId =? and em.firstname =? and em.jobid =?
Select * from employees where em em. empId =? and em.firstname =?
I need to write a query that is used internally this time condition and return records
Select * from employees where em
If (EM.) JobID is nothing)
{
Select * from employees where em em. empId =? and em.firstname =?
}
on the other
{
Select * from employees where em em. empId =? and em.firstname =? and em.jobid =?
}
How could I write this problem in sql?Hello
You can try the following:
Select * from employees where em em. empId =? and em.firstname =? and (em.jobid =? or em.jobid is null).Kind regards
Rommel Pino
http://soadev.blogspot.com -
Need to write a different SQL query
Oracle version: 11.2.0.4
create visitors from the table (name varchar2 (10), dated $vdate);
Insert values ('John', sysdate-3) visitors;
Insert values ('John', sysdate-2) visitors;
Insert values visitors ('John', sysdate + 1);
Insert values visitors ('Thomas', sysdate-5);
Insert values visitors ('Thomas', sysdate-4);
Insert values visitors ('Thomas', sysdate + 2);
Insert values visitors ('Adam', sysdate + 1);
Now I need to find the max for each visitor with the name $vdate. I wrote the query below and I'm
My expected results.My query:
Select * from (name, $vdate, dense_rank (select) on mxdate (partition by name $vdate desc order)
visitors)
where mxdate = 1;Output:
NAME $VDATE
John May 14, 2015
Thomas may 15, 2015
Adam, 14 may 2015Can someone write this query using the EXISTS or NOT EXISTS with below terms?
1. without using the aggrgeate function
2. without using the analytic functionThanks for your help in advance...
Note: This is not the original data. This is only the test data...
Something like
Select * from v1 visitors
where does not exist (select 1 of visitors v2 where v1.name = v2.name and v1.vdate<>
NOT TESTED.
-
How to write this query in the hierarchy
Hi gurus,
Really need your help on this query. Thank you very much in advance.
SELECT t1.key as root_key , (SELECT t2.unit_id AS unit_id level-1 AS level , t2.name, t2.creator FROM tab t2 START WITH t2.unit_id = t1.unit_id -----check each node as root CONNECT BY prior t2.unit_id = t2.parent_unit_id ) t1.name as parent_unit_name FROM tab t1
I'll write a query of the hierarchy as above, and that EACH line (node, totally more than 10200) is checked as root node to see how many sheets are accessible for her... It must be implemented in a single query.
I know inline query should NOT return multiple rows or multiple columns, but the inline elements are necessary and can certainly be made in a correct solution.
(env):
Database Oracle 12 c Enterprise Edition Release 12.1.0.2.0 - 64 bit Production
PL/SQL Release 12.1.0.2.0
)
Test data:
select 1 as unit_id, null as parent_organization_unit_id, 'U1' as name from dual union all select 2, 1, 'U2' FROM DUAL UNION ALL SELECT 3, NULL, 'U3' FROM DUAL UNION ALL SELECT 4, 3, 'U4' FROM DUAL UNION ALL SELECT 5, 2, 'U5' FROM DUAL UNION ALL SELECT 6, 5, 'U6' FROM DUAL UNION ALL SELECT 7, 6, 'U7' FROM DUAL UNION ALL SELECT 8, 5, 'U8' FROM DUAL UNION ALL SELECT 9, 5, 'U9' FROM DUAL;
Final result should be like this
key unit_id, level, name, parent_name 1 1 0 u1 u1 1 2 1 u2 u1 1 5 2 u5 u1 1 6 3 u6 u1 1 7 4 u7 u1 1 8 3 u8 u1 1 9 3 u9 u1 2 2 0 u2 u2 2 5 1 u5 u2 2 6 2 u6 u2 2 7 3 u7 u2 2 8 2 u8 u2 2 9 2 u9 u2
Don't know how get you your output, it does not match your data...
with tab as)
Select 1 as unit_id, null as parent_organization_unit_id 'U1' as the name of double
Union of all the
Select 2, 1, 'U2' FROM DUAL
UNION ALL
SELECT 3, NULL, 'U3' FROM DUAL
UNION ALL
SELECT 4, 3, 'U4' FROM DUAL
UNION ALL
SELECT 5, 2, 'U5' OF THE DOUBLE
UNION ALL
SELECT 6, 5, 'U6' OF THE DOUBLE
UNION ALL
SELECT 7, 6, "U7" OF THE DOUBLE
UNION ALL
SELECT 8, 5, 'U8' FROM DUAL
UNION ALL
9. SELECT, 5, 'U9' FROM DUAL
)
Select dense_rank() key (order by connect_by_root unit_id), unit_id, level - 1 as 'LEVEL', connect_by_root name root_parent_name
t tab
Start with parent_organization_unit_id is null
Connect prior unit_id = parent_organization_unit_id
KEY UNIT_ID LEVEL ROOT_PARENT_NAME 1 1 0 "U1". 1 2 1 "U1". 1 5 2 "U1". 1 6 3 "U1". 1 7 4 "U1". 1 8 3 "U1". 1 9 3 "U1". 2 3 0 "U3". 2 4 1 "U3". -
How to write a query to join and right join
Hello
With the help of 10 gr 2:
I have a scenario where generate us a report by joining a few tables.
same goes for ex:
Select col1, col2, col5, col10 col22...
from tableA, tableB.
where tableA.col1 = tableB.col1 etc.
I have a requirement where choose a flag in the front-end server must be a right join. so, if the flag is N, I need to return the data returned by the join; but, if the flag is there I need to make a right join and returns all the data corresponding to table A and table B, as well as the data in table B.
(I did mention only two tables, as they are, they main engines, there are very many other tables joined in this request)
It is possible to write a query, so that the two scenarios can be addressed based on the flag?
Thanks in advance
Hello
user565033 wrote:
... When Oracle treats of the WHERE clause that starts from the bottom or the top? So it's best to put filters that reject the unnecessary lines at the beginning of the place where clause or end? Is how important it? ...
No, it does not matter.
The optimizer evaluates what condition will be faster and/or more selective (that is, will eliminate the most lines) and make the first condition.
If the optimzer cannot decide on what terms will be faster or more selective, it can arbitrarily don't close at the end of the WHERE clause first, but, even if you already knew for sure, this is exactly the kind of thing that is likely to change from one version to the other, or platform to another.
The optimizer (in recent versions, at least) is very good. If the optimizer can not say what conditions should apply first, then, chances are, there is really no significant difference, so it would be not serious of which one was made first.
If you read something that indicates the order is important, it is very outdated. Long ago (version 6), there was no cost-based optimizer and the order of the conditions in the WHERE clause was important. The cost-based optimizer was introduced in Oracle 7 (1992) and has been greatly improved by Oracle 8.1 (1998). Also later Oracle 10, the older optimizer ("regulated") was available for those who really want to continue to use it.
-
How can I write a query to siolate the value after the decimal point
This query
Returns the following output (just an example I like 1,000 records that I need to fix)select spraddr_pidm, SPRADDR_CITY from spraddr where SPRADDR_NATN_CODE = 'CA' and SPRADDR_ATYP_CODE = 'AH'
As you can see that providence is inserted into the column city (SPRADDR_CITY)140804 Toronto, Ontario 140832 Quebec, Quebec 140845 Halifax, NS 140889 Mississauga, Ontario 140902 Boucherville, Quebec 140945 Westmount, Quebec 136971 Montreal, Quebec 180650 Granby, Quebec 137007 Quispamsis, NB 137037 Varennes, Quebec 180746 Port Williams, NS
I want to break the column and isolated from providence, so I can insert into a custom table
the city and providence, so I can fix the files...
I guess the question is how do I write a query to isolate the providence...
Thank youHello
Here's one way:
WITH got_comma_pos AS ( SELECT spraddr_pidm , spraddr_city , INSTR ( spraddr_city || ',' , ',' ) AS comma_pos FROM spraddr WHERE spraddr_natn_code = 'CA' AND spraddr_atyp_code = 'AH' ) SELECT spraddr_pidm , SUBSTR (spraddr_city, 1, comma_pos - 1) AS city , LTRIM (SUBSTR (spraddr_city, 1 + comma_pos)) AS province FROM got_comma_pos ;
What do you do if there is no comma in spraddr_city? The above query assumes that the entire string is the name of the city in this case and the province with a NULL value.
You can also use regular expressions, but this way is more effective and about as simple to code.
-
Another way to write the query:
Dear Experts, I am a beginner in sql. With my knowledge, I wrote this query
but he took great moment in my database 11g
Please tell any alternative to write this query in another way to increase performance
Please find the explanation below
SELECT DISTINCT * FROM UPGRADATION r1, LOG t2, OMNIACCOUNT m1, (SELECT rid , LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY ACCOUNTNO) AS ACCOUNTNO FROM OMNIACCOUNT GROUP BY rid) mk3, (SELECT mobileno , LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY ACCOUNTNO) AS ACCOUNTNO FROM OMNIACCOUNT GROUP BY mobileno) mk1, (SELECT mobileno , LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY accounttype) AS ACCOUNTTYPE FROM OMNIACCOUNT GROUP BY mobileno) mk2 WHERE t2.txnauthid = r1.txnauthid AND r1.rid = mk3.rid AND t2.txntype = '54' AND mk1.mobileno = r1.regmobileno AND t2.reqtype = '11' AND t2.dc_id IN (SELECT deliverychannel_id FROM Channel) AND t2.custbankcode = '32472' AND t2.txndatetime BETWEEN TO_DATE ('28/12/2011 12:00:00 AM', 'DD/MM/YYYY hh:mi:ss AM' ) AND TO_DATE ('28/12/2012 11:59:59 PM', 'DD/MM/YYYY hh:mi:ss PM' ) AND r1.rid = m1.rid(+) AND t2.txnstatus IN ('C', 'F', 'T') AND t2.paymentinitiator = 'C' AND mk1.mobileno = mk2.mobileno Explain Plan For the above statement : ----------------------------------- SELECT STATEMENT FIRST_ROWSCost: 16 Bytes: 4,270 Cardinality: 1 25 HASH UNIQUE Cost: 16 Bytes: 4,270 Cardinality: 1 24 NESTED LOOPS Cost: 15 Bytes: 4,270 Cardinality: 1 19 NESTED LOOPS Cost: 14 Bytes: 4,270 Cardinality: 1 13 HASH JOIN Cost: 13 Bytes: 2,268 Cardinality: 1 9 NESTED LOOPS OUTER Cost: 4 Bytes: 252 Cardinality: 1 7 NESTED LOOPS Cost: 3 Bytes: 239 Cardinality: 1 4 NESTED LOOPS Cost: 2 Bytes: 119 Cardinality: 1 2 TABLE ACCESS BY INDEX ROWID TABLE LOG Cost: 1 Bytes: 116 Cardinality: 1 1 INDEX RANGE SCAN INDEX IX_LOG Cost: 1 Cardinality: 8 3 INDEX UNIQUE SCAN INDEX (UNIQUE) PK_Channel Cost: 1 Bytes: 3 Cardinality: 1 6 TABLE ACCESS BY INDEX ROWID TABLE UPGRADATION Cost: 1 Bytes: 120 Cardinality: 1 5 INDEX RANGE SCAN INDEX IDX_REG_AUTH Cost: 1 Cardinality: 1 8 INDEX RANGE SCAN INDEX IDX_MLTN_BNK_ACCT Cost: 1 Bytes: 13 Cardinality: 1 12 VIEW Cost: 8 Bytes: 1,110,816 Cardinality: 551 11 SORT GROUP BY Cost: 8 Bytes: 16,530 Cardinality: 551 10 TABLE ACCESS FULL TABLE OMNIACCOUNT Cost: 7 Bytes: 21,210 Cardinality: 707 18 VIEW PUSHED PREDICATE Cost: 1 Bytes: 2,002 Cardinality: 1 17 FILTER 16 SORT GROUP BY Bytes: 33 Cardinality: 1 15 TABLE ACCESS BY INDEX ROWID TABLE OMNIACCOUNT Cost: 1 Bytes: 33 Cardinality: 1 14 INDEX RANGE SCAN INDEX IDX_MUL_LNKG Cost: 1 Cardinality: 1 23 VIEW PUSHED PREDICATE Cost: 1 Cardinality: 1 22 FILTER 21 SORT GROUP BY Bytes: 29 Cardinality: 1 20 INDEX RANGE SCAN INDEX IDX_MLTN_BNK_ACCT Cost: 1 Bytes: 29 Cardinality: 1
It would be best to leave the desired projection.
Probably you don't really want all columns form this query.
However, these are your join criteria:t2.txnauthid = r1.txnauthid AND r1.rid = mk3.rid AND r1.regmobileno = mk1.mobileno AND mk1.mobileno = mk2.mobileno AND r1.rid = m1.rid(+)
Maybe you can get rid of AND mk1.mobileno = mk2.mobileno
with(SELECT mobileno , LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY ACCOUNTNO) AS ACCOUNTNO , LISTAGG(ACCOUNTNO, ',') WITHIN GROUP (ORDER BY accounttype) AS ACCOUNTTYPE FROM OMNIACCOUNT GROUP BY mobileno)
After the combination seems to be suspicious:
AND r1.rid = mk3.rid AND r1.rid = m1.rid(+)
The first limit the result on all lines with the same id in
OMNIACCOUNT and UPGRADATION
so, o see no gain from the outer join.Do you really need the listagg on all OMNIACCOUNT lines.
If this isn't the case, it would be probably better to do the listagg in the final projection.Maybe one way could be to start with OMNIACCOUNT and join outer UPGRADATION to it.
You can do the listagg at the end.Maybe something like
select * from OMNIACCOUNT m1 left outer join (Select projection goes here from log t2 join UPGRADATION r1 on r1.txnauthid = t2.txnauthid AND t2.reqtype = '11' AND t2.dc_id IN (SELECT deliverychannel_id FROM Channel) AND t2.custbankcode = '32472' AND t2.txndatetime BETWEEN TO_DATE ('28/12/2011 12:00:00 AM', 'DD/MM/YYYY hh:mi:ss AM' ) AND TO_DATE ('28/12/2012 11:59:59 PM', 'DD/MM/YYYY hh:mi:ss PM' ) AND t2.txntype = '54' AND t2.txnstatus IN ('C', 'F', 'T') AND t2.paymentinitiator = 'C' ) r1 on m1.rid=r1.rid AND r1.regmobileno = m1.mobileno
Published by: chris227 on 10.01.2013 01:45
fix -
I need to write a report that would be altogether retained for a pay period. There will be 2 p_year and p_quarter parameters
sample:
pay the amount to be deducted for period emp_code
1 XXX 2,300.00
1 Q XXX PLACES 1 399.00
2. IS XXX 2,300.00
2 Q XXX 1,400.00
There are 3 tables: calendar_table, amount_table, and deduction_codes picture
calendar_table
p_year
p_payno
p_check_date
deduction_codes
Code_P
p_code_desc
deduction_amounts
p_year
p_payno
p_deduction_code
p_amount
Here's my query:
SELECT c.deduction_code as deduction_code,
d.emp_code as emp_code,
Sum (d.employee_amt) as the amount
Deduction_amount d, deduction_codes c
WHERE d.year = p_year
AND IN d.pay_period (this is the part where I need to get all the pay periods for the entered setting)
AND d.deduction_code = c.deduction_code
C.deduction_code GROUP, d.emp_code
ORDER BY c.deduction_code;
I have a few problems:
If the user is going to happen in the YEAR and the quarter, how do I change my query? Lets say that she entered the YEAR = 2009 and QTR = Q1, whats going to happen to my request? BTW, in the table of calendar for each year there are 26 pay periods. I can use the check_date field to determine if the pay period belongs to which quarter. I don't know how to do.
Thanks in advance!
Published by: user5737516 on November 2, 2009 18:46
Published by: user5737516 on November 2, 2009 18:54
Published by: user5737516 on November 2, 2009 18:56
Why does nobody answer?Good to know that we are of little help.
So problem solved please pay points and close the debate.See you soon!
Bobin -
I have a generator of two impulses. I need to write to a file the three intervals Ao0
I have a two train pulses a 6009. They are Ao0 Ao1. Ao0 output will produce the total time on my meter. The façade shows 3,1,3. I can run the relay very well. I need to write about my 'Write to file - LVM' the same 3 intervals in time. Write after 3 seconds, the overall data. After 1 second, then after 3 seconds more.
Thank you
Philippe
wrong file
-
Oracle Version: 11.2.0.2.0
I need assistance with the output of the query. Here is the table.
With Tbl_Nm as
(
Select 'ABC1' SYSTEM_ID, REGION 'US', 'CHI' SUB_REGION 4000 BALANCE, to_date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') LAST_UPD_TIME, 'A' FLAG of union double all the
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select * from tbl_nm
I need the output below.
PQR2 UK MC 2600 1 OCTOBER 2012 04:45
ABC1 US NY 3500 October 1, 2012 06:45
LMN3 UK BT 2500 November 1, 2012 07:45
The need the disc according to this system_id flagged as "A". But if the last disc of 'd' then it must show that the amount, but the file should be displayed in 'A '.
I've tried a few and got stuck. Help, please. Not able to get a balance '.
This question is a bit similar to needing help with a query result
With Tbl_Nm as
(
Select 'ABC1' System_Id, region 'US', 'CHI' Sub_Region, 4000 balance, To_Date('1-JUN-2012 10:45:00 am', 'dd-mon-yyyy hh:mi:ss am') Last_Upd_Time, 'A' flag of double Union All
Select 'PQR2', 'UK', 'LN', 2000, To_Date('1-JUL-2012 10:46:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select 'ABC1', 'IND","MAMA", 3500, To_Date('1-AUG-2012 11:47:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "LMN3", "US", "NJ", 2500, To_Date('1-SEP-2012 09:49:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select "PQR2", "UK", "MC", 2600, To_Date('1-OCT-2012 04:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), 'A' from dual Union All
Select 'ABC1', 'US', 'NY', 3200, To_Date('1-OCT-2012 06:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' starting from dual Union All
Select "LMN3", "UK", "BT", 2400, To_Date('1-NOV-2012 07:45:00 am', 'dd-mon-yyyy hh:mi:ss am'), has ' From Dual
)
Select System_Id, region, Sub_Region, Balance, Last_Upd_Time of Tbl_Nm T1
where t1. Last_Upd_Time = (select max (Last_Upd_Time) in the Tbl_Nm T2 where T1.) SYSTEM_ID = T2. SYSTEM_ID)
So maybe you'd then
ORDER BY DECODE(flag,'D',9,1) ASC...
to get the Ds at the end of the list.
or
ORDER BY CASE WHAT flag = has ' (your other filters) AND then 9 or 1 end CSA,...
HTH
-
How to write a query to return rows with the varchar column that contains even a single occurrence of the characters, such as Ÿ and
I have a table whose columns with values such as
MINNEAŸPOLIS and ¿VV ¿A
Only the characters that are allowed in this column are alphabets, numbers, spaces, points and supports.
Please help to write a SQL SELECT with Regexp_like query or any other option.
Thanks to you all! Under query worked for me. Thank you Frank to explain the concept of hooks inside regexp_like.
SELECT * FROM testspecial, WHERE REGEXP_LIKE (sampletext, "[^] ^ A - Z ^ a - z ^ 0-9 ^ [^.]") ^ {^} ^]') ;
-
How to write this query?
Hi people,
I need to get a query in which a set of records, I get ONLY those which previous registry has a field with a value to this topic. Other values, the field can contain are not necessary.
I know that sounds easy but... I can't get it.
So, for Oracle 10 g 2... Here's my query:
SELECT a.person_id, a.person_status, a.message_id, a.order_id
OF t_HR one
WHERE a.person_status = "rejected".
AND a.id >
(SELECT max (b.id)
OF t_HR b
WHERE b.person_id = a.person_id
and b.order_id = a.order_id
AND b.person_status! "revised =".
B.ID AND < a.id)
ORDER BY desc a.id
Let me explain:
1 - HR table is a table of people. These people has serveral STATUS.
2 - ID is a sequential (each www.voyages-sncf.com has a different identification number).
3 - the application must get THAT all people "rejected".
4. - However, (subquery) I need ONLY those that previous register (the second register) holds a status of "OK". If the person holds a "revised" status he's not, he should be the next register (the third)
5.-L' ORDER ID DESC, so is the first register must have a STATUS = "rejected" and the second a 'OK '. IF the second register = "revised", then the third register must be 'OK '. And I need this query.
HOW DO?
My problem: the subquery gives you previous register of the same guy, but... it does not give you the value of the State, I need, which is 'OK '.
I tried to add to the subquery...
SELECT max (b.id)
OF mod_human_resource b
WHERE b.person_id = a.person_id
and b.order_id = a.order_id
AND b.person_status = 'OK '.
AND b.id < a.id
... but if I have 5 records of that person, the first is "rejected", the second is "accepted", the third is 'new' and the fourth is 'OK'... the subquery gives you the 4th register and which is not correct for me, it must be only the second one (prior to the first State registry).
I need to be a query, because I need to use it on a MERGER for a DWH.
If there is another way (function, or even a procedure) to make the MERGER rather than with a request, which would be ok too. I am poor DWH knowledge.
Thanks in advance.
Hello
So, you need to know if a line is the 'first' line, and you should also know what is the 'next' status, (even the 'first' and 'next' are already defined). This sounds like a job for analytical functions. ROW_NUMBER can tell you if a line is first or not, and LEAD can tell you what a value on the next row.
Since you post CREATE TABLE and INSERT statements for your own table, I'll use the table scott.emp to illustrate.
Consider these data from scott.emp:
SELECT DeptNo
ename
work
FROM scott.emp
ORDER BY deptno
ename DESC
;
Output:
DEPTNO ENAME JOB
---------- ---------- ---------
10 MILLER CLERK
PRESIDENT OF KING 10
MANAGER 10 CLARK
20 SMITH CLERK
ANALYST SCOTT 20
20 JONES MANAGER
20 FORD ANALYST
20 ADAMS CLERK
30 WARD SALESMAN
SELLER OF 30 TURNER
30 MARTIN SALESMAN
30 JAMES CLERK
MANAGER BLAKE 30
30 ALLEN SALESMAN
Now, let's say we want only who know the departments where the forefront (in order descending ename) a job = 'CLERK', and the following line (also in descending by ename order) = "ANALYST" job, and we want to know the ename of the first row. In other words, the correct output is:
DEPTNO ENAME
---------- ----------
20 SMITH
Note that deptno = 10 is not included, even if the first task is to "CLERK." that was because the second job in deptno = 10 is the "PRESIDENT", not "ANALYST."
Here's a way to get these results:
WITH got_analytics AS
(
SELECT ename, deptno, job
ROW_NUMBER () OVER (PARTITION BY deptno
ORDER BY ename DESC
) AS r_num
LEAD (employment) OVER (PARTITION BY deptno
ORDER BY ename DESC
) AS next_job
FROM scott.emp
)
SELECT deptno, ename
OF got_analytics
WHERE r_num = 1
AND job = 'CLERK '.
AND next_job = 'ANALYST '.
;
I hope that answers your question.
If this isn't the case, then, as Dan (and the FAQ forum) said, post CREATE TABLE and INSERT statements for some sample data and the exact results you want from these data.
Post your query, based on the one I have posted more top and ponit out where he gets results.
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#9362002
-
Hi, I need to install Adobe Flash Player, because the version I have installed on my Mac Os is old, but I can´t do it because I need to write my email and my password and I Don t remember my password, what can I do? Thank you
Email and the password will be the security of your computer, not something for all Adobe products. You may need to consult the Mac clients if you are unable to determine the required information.
-
How to write the query option in expdp
Hi Please someone help me how to write the query option in expdp... .in expdp using the query option...
where AM columnname between 5 May 12 02:57:00.000' and ' 02:59:59.999 6 May 12: ';
Please do what is necessary...Pavan Kumar says:
QUERY = (columnname scott.test: "where between 5 May 12 02:57:00.000 h ' and ' 6 May 12 AM 02:59:59.999'")Who will fail in databases, because you assume nls_date_format. How it is difficult to put to_date() surround channels? Rather than play with quotation marks, using one parfile thusly.
query=table_owner.table_1:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')" query=table_owner.table_2:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')" query=table_owner.table_3:"where business_date between to_date('20120505025700 am','yyyymmddhhmiss am') and to_date('20120505025959 am','yyyymmddhhmiss am')"
You do not have to have all the clauses in a single line, as they are side by side parfile, which would be enough. For this reason parfile is better than the command line in order to avoid all the back-citing dance.
Maybe you are looking for
-
How to remove all items in the download under bookmark folder in the shortest time?
I understand that all downloads from the internet and yahoo/google mail are stored in the "Download" folder I bookmarked when I want to delete. I think that if the download folder is never empty, then my mac will slow down. So I want to remove these
-
Graph XY on the custom user Interface
Hello. I'm kinda stuck (or really stuck ). In any case, I'm newbie. That being said, I've had a few really good help on how to pass table through the postuimessage (xparamdata) of teststand to my user interface customized a few weeks ago. It real
-
Problems with fingerprints in Windows 7 and HP 8510
I have 8510 HP with windows 7 ultimate x 64. Thanks to differentiate clear installation... I did all the steps, but it keeps saying that my sensor is not detected! I installed the drivers for the sensor, but windows has also updated the driver as wel
-
Why my computer pavilion laptop, it starts and seconds later, just stops
Im working on a pavilion entertainment pc and when I go to boot it it stays on for a brief second then stops I was wondering why its done this for as far as I know nobody has never opened to make adjustments
-
I CAN'T OPEN MY ATTACHMENTS IN WINDOWS LIVE MAIL...
EVERYTHING THAT IS TRYING TO OPEN WITH WINDOWS MEDIA PLAYER AND I CAN'T CHANGE IT FOR SOME REASON ANY!