Ask the deptno 20 last record at the end show
Oracle 9i DatabaseI want to create a query that shows records, Deptno 20 last record at the end.
application of shot show all records that are in the emp table.
SQL> select empno,ename,job,deptno, row_number() over (order by deptno) rno from emp;
EMPNO ENAME JOB DEPTNO RNO
---------- ---------- --------- ---------- ----------
7782 CLARK MANAGER 10 1
7839 KING PRESIDENT 10 2
7934 MILLER CLERK 10 3
7369 SMITH CLERK 20 4
7876 ADAMS CLERK 20 5
7902 FORD ANALYST 20 6
7788 SCOTT ANALYST 20 7
7566 JONES MANAGER 20 8
7499 ALLEN SALESMAN 30 9
7698 BLAKE MANAGER 30 10
7654 MARTIN SALESMAN 30 11
EMPNO ENAME JOB DEPTNO RNO
---------- ---------- --------- ---------- ----------
7900 JAMES CLERK 30 12
7844 TURNER SALESMAN 30 13
7521 WARD SALESMAN 30 14
14 rows selected.
SQL>
I want the resultEMPNO ENAME JOB DEPTNO RNO
---------- ---------- --------- ---------- ----------
7566 JONES MANAGER 20 8
7499 ALLEN SALESMAN 30 9
7698 BLAKE MANAGER 30 10
7654 MARTIN SALESMAN 30 11
7900 JAMES CLERK 30 12
7844 TURNER SALESMAN 30 13
7521 WARD SALESMAN 30 14
Concerning
with t as
( select 7782 e1,'CKING ' e2 , ' PRESIDENT ' e3 , 10 e4 from dual union all
select 7934, 'MILLER' , 'CLERK ' , 10 from dual union all
select 7369, 'SMITH ' , 'CLERK ' , 20 from dual union all
select 7876, 'ADAMS' , 'CLERK ' , 20 from dual union all
select 7902, 'FORD ' , 'ANALYST ' , 20 from dual union all
select 7788, 'SCOTT' , 'ANALYST ' , 20 from dual union all
select 7788 ,' SCOTT ' ,'ANALYST ' , 20 from dual union all
select 7566, 'JONES ', 'MANAGER ' , 20 from dual union all
select 7499, 'ALLEN ' , 'SALESMAN' , 30 from dual union all
select 7698, 'BLAKE ' , 'MANAGER ' , 30 from dual union all
select 7654, 'MARTIN' , 'SALESMAN ' , 30 from dual union all
select 7900, 'JAMES ' , 'CLERK ' , 30 from dual union all
select 7844, 'TURNER' , 'SALESMAN ' , 30 from dual union all
select 7521 ,'WARD ' , 'SALESMAN ' , 30 from dual
)
SELECT o.*
FROM (SELECT p.*,
MAX (CASE
WHEN p.e4 = 20
THEN p.rno
END) OVER (ORDER BY p.e4) AS mx
FROM (SELECT a.*, ROW_NUMBER () OVER (ORDER BY e4) rno
FROM t a) p) o
WHERE o.rno >= o.mx
Tags: Database
Similar Questions
-
Properties of the file - Date of the last recorded
Hello.
I'm having trouble understanding the properties of the file, as "Last record Date" (DLS) and "Date modified" (MD).
I asked that the last of them, MD, has been changed whenever the content has changed. But Distribution lists must be updated also.
However, I have a file which has the DLS on 2007 and MD 2014 and the 'last impression"also is 2014.
How is that possible?
What has changed the date the content of the file was really the last?
I would be grateful if someone could help me understand this.
Thank you,
Nuno Roque
Modification date is when the file got changed on that hard drive. Even if you have never opened the file, just drag-and - drop it to drive flash (for an example) would last updated date change, because the file on this disk changed really.
Properties such as "Date of last recorded" and "date printed" are stored in the file itself, such as metadata and are updated no not by disk or operating system, but by the design (such as Word) program.
-
ask the last disk in per_assignments_v
Hello
I would like to ask how to query the per_assignments_v table to return only the last record.
When pointed out that it will create another record whenever you update from the form.
Thank you
Rey
Hey Rey,
The feature you're looking for is called follow-up Date.
Check-
https://blogs.Oracle.com/manojmadhusoodanan/entry/date_tracking_in_oracle_hrms
Basically all _F tables store data for a period of time, so you always get data from a timestamp.
SQL, you include sysdate between effective_start_date and effective_end_date for all the joins of tables _F.
Hope that helps,
See you soon,.
Vignesh
-
Select the last record of each month
Hello
to select the last docnumber and qty of every month
Structure
Name Null? Type
------------------------------- -------- ----
PRODUCTCODE NUMBER
NUMBER NUMBER
DATE OF PLANFORMONTH
NUMBER OF CLEXPECTEDQTY
NUMBER OF CLCONFIRMQTY
NUMBER OF CLFGBUFFERQTY
NUMBER OF CLTOTPRINTBUFFER
in this select query if I take the sum he required all records where, as I want the last record of each month
SELECT productcode docnumber MAX (Number), planformonth, SUM (clexpectedqty) clexpectedqty (planformonth) MAX.
SUM (clconfirmqty) clconfirmqty, SUM (clfgbufferqty) clfgbufferqty, cltotprintbuffer OF FGSALESPLAN of the SUM (cltotprintbuffer)
GROUP BY productcode, (planformonth)
Sandy
Hello
Thanks its working now the code is written as below:
SELECT * FROM
(SELECT
e.*,
ROW_NUMBER() OVER (partition by PRODUCTCODE by DOCNUMBER DESC order) r
Of
E FGSALESPLAN)
WHERE r = 1 AND
entryvalid = 'Y '.
order by Number
Sandy
-
Reader Adobe XI updates last week. Reinstalled this morning. All previous saved pdf files are now forms of words asking the conversion? Creates problems for my business. Help, please?
See http://windows.microsoft.com/en-us/windows/change-file-open-program#1TC=windows-7
Another method: http://windows.microsoft.com/en-us/windows/change-default-programs#1TC=windows-7
-
Add a string to the last record
Hello
I was just trying to format an o/p to a table, and looking at the result, I thought it would be nice to add a piece of a chain to the last record. For example
with dat as ( select 'First Record' as COL from DUAL union all select 'Second Record' from DUAL union all select 'Third Record' from DUAL union all select 'Nth Record' from DUAL ) select * from dat o/p Desired o/p COL COL ------------- ------------- first RECORD first RECORD second RECORD second RECORD THIRD RECORD THIRD RECORD NTH RECORD This is the last record NTH RECORD
with dat as ( select 'First Record' as COL from DUAL union all select 'Second Record' from DUAL union all select 'Third Record' from DUAL union all select 'Nth Record' from DUAL ), ord as ( select count(*) rn from dat ) select decode(rownum, rn, 'This is Last Record ' || col, col) from ord, dat;
-
How to find the last record of the extracted records
Dear members,
I have an OFA Page in which I view record master detail. For each master record can one or more detail records.
In the page I got the button NEXT. If the user clicks the next button, I'm populating the next record of the master and its corresponding detail records.
To achieve this, I wrote the code below in AM:_
Public Sub findNextRec()
*{*
String headerID = null;
Rank rank is getMaster_VO1 () .next ();.
if(Row!=null)
*{*
headerID = row.getAttribute ("HeaderId") m:System.NET.SocketAddress.ToString ();
getDetail_VO1 (.setMaxFetchSize(-1));
getDetail_VO1 () .setWhereClause (null);
getDetail_VO1 () .addWhereClause ("header_id in (: 1)" ");
getDetail_VO1 () .setWhereClauseParams (null);
getDetail_VO1 (.setWhereClauseParam(0,headerID));
getDetail_VO1 () .executeQuery ();
*}*
*}*
My CO code in processFormRequest method is as follows:_
If (PageContext.GetParameter ("Next")! = null)
*{*
am.invokeMethod ("findNextRec");
*}*
Here my requirement is that if it's a last drive, I want to show the user a message saying it's last recording. To achieve this please let me know what the code should be written.
Thanks in advance.
Best regards
Arun D. ReddyArun,
If my interpretation is correct, then you can achieve the same thing by making some minor changes to your existing code.
public void findNextRec() { String headerID=null; Row row = getMaster_VO1().next(); if(row!=null) //your code will return null when if there is no record { headerID=row.getAttribute("HeaderId").toString(); getDetail_VO1().setMaxFetchSize(-1); getDetail_VO1().setWhereClause(null); getDetail_VO1().addWhereClause("header_id in (:1)"); getDetail_VO1().setWhereClauseParams(null); getDetail_VO1().setWhereClauseParam(0,headerID); getDetail_VO1().executeQuery(); } else{ //write down the message that there exist no more rows (custom message) } }
Kind regards
GYAN -
How to find inserted last record in the table.
Version: Oracle 10g
I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
How to find inserted last record in the table 'manufacturing '.
As I got to know that the Rowid is not a result perfect result. Please provide your inputs.user13416294 wrote:
Version: Oracle 10gThis is not a version. It's a product name. A version is 10.1.0.2 or 10.2.0.4, etc.
I have a table called 'Manufacturing' and 3 columns as mfno, itemname, quantity.
How to find inserted last record in the table 'manufacturing '.Not possible as your data model do not answer for him. As simple as that.
If there is a need to determine an order or associate some time to an entity, then that should be part of the data model - and a relationship, or one or several attributes are necessary to represent this information. Your data model in this case is therefore unable to meet your requirements.
If the requirements are valid, set the data model. In other words - your question has nothing to do with Oracle and nothing to do with the other pseudo columns in Oracle, the rowscn or the rowid. It is a question of pure data modeling. Nothing more.
-
How to get the first and last record
Hai All
I have a table called T1 and there are more than 8 lakhs Archives and I have a column named Timestamp, so I need to get the first record value and time stampvalue and last record and time stamp value so that I can conclude that for example
form June 13 to 15 June data are here
Kind regards
SrikkanthMWhat is the problem with:
select min(timestamp),max(timestamp) from T1;
?
-
Insert correctly last record to the child table in the multi user environment.
Hello
I have the following situation.
Two Tables
Table1 has a primary key named ID column
Tabel2 contains a column named table1_id, this is a foreign key to table1.
I have a tabular report that contains an add record button and a button submit to table1. (this table has other columns that require attribution)
I want to insert a record into table2 automatically whenever the user presses submit.
I have a query like this to get the last record in table1:
and I would use it in a submit after procedure like this:SELECT MAX(id) FROM table1
The thing that worries me, is that the application that I use is a multi user environment. I'm afraid that if two or more people use as MAX recording is not the right one.DECLARE v_id NUMBER; BEGIN SELECT MAX(id) INTO v_id FROM table1 INSERT INTO table2(table1_id) VALUES (v_id); END;
It's a legitimate concern?
If so, is there a best way to do this kind of thing.Ben:
The triggers are usually avoidable IMO. But, there is always a but, you already use triggers elsewhere in your application, and probably your form the apex uses the routines of APEX MRU for DML and thus leaves the trigger as the only viable option to achieve what you're trying to do.
CITY
-
calculation of ratios and rounding - how the sum of last record to give 1
I'm putting in a single query to calculate the reports for an unknown number of records. I want to turn the ratios to 5 decimal places and I want the total reports of equal to 1.
for example
If I have 3 folders with Qty total overal 4,5,6 is 15
I note 3 lines
Round (4/15.5),
Round (5/15.5),
Round (6/15.5)
but I want to ensure total = 1
so I will try to do something like
Round (4/15.5),
Round (5/15.5),
1 - round(4/15,5) - round(5/15,5)
can someone help show me the sql construction? I've been trying and failing using where clause
of course this example would add to 1 but other unknown ratios may not match up to 1.
Published by: user12154024 on November 2, 2009 22:32Hello 12154024,
Welcome to the forum. May not be a more elegant solution, but it shows how it works step by step
WITH t AS ( SELECT 4 n FROM dual UNION ALL SELECT 5 n FROM dual UNION ALL SELECT 6 n FROM dual ) ,t1 AS ( SELECT n ,ROUND(RATIO_TO_REPORT(n) OVER (),5) AS rr ,COUNT(n) OVER () AS c ,ROW_NUMBER() OVER (ORDER BY n) AS rn FROM t ) ,t2 AS ( SELECT n ,rr ,SUM(rr) OVER (ORDER BY n) s ,c ,rn FROM t1 ) SELECT n ,rr ,CASE WHEN c = rn THEN rr + (1 - s) ELSE rr END rr2 ,s FROM t2 ORDER BY rn; N RR RR2 S --- --------- --------- -------- 4 0.26667 0.26667 0.26667 5 0.33333 0.33333 0.6 6 0.4 0.4 1 3 rows selected
The part "WITH t AS" generates data
T1 calculate the ratio, counts the number of records and signs a current issue
T2 to calculate a cumulative ratio
the last part takes these data and for the last record (number = count running) it allows to adjust the ratio.You can see if you are using other data
WITH t AS ( SELECT 4.78 n FROM dual UNION ALL SELECT 5 n FROM dual UNION ALL SELECT 6 n FROM dual ) ... N RR RR2 S ---- -------- -------- -------- 4.78 0.30292 0.30292 0.30292 5 0.31686 0.31686 0.61978 6 0.38023 0.38022 1.00001 3 rows selected
Concerning
Marcus -
remove the last record from the plsql table
Under certain conditions, I need to remove the last record from i_CustomerLoopTYPE r_LOOPElement IS RECORD (TermID NUMBER ); TYPE t_LOOPType IS TABLE OF r_LOOPElement INDEX BY BINARY_INTEGER; i_CustomerLoop t_LOOPType ; i_CustomerLoop(1).TermID=1; i_CustomerLoop(2).TermID=2; i_CustomerLoop(3).TermID=3;
whichi s the best way to do it. because I sometimes get duplicates for TermID in this plsql table.Hello
See [removing items from Collection (DELETE method) | http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/collections.htm#CJAFGFIG]
Kind regards
-
What is the best way to get the last record in a table?
... in addition to select * from tbl by id Desc... & then set = 1 maxrow in cfoutput.
I want a quick way.
I tried "Max (id), columns, but not worked.
If I ' Max (id) as V ' & then turn around and make another request for ' where id = #V # "to get the rest of the record, there's more action.
Quote:
Posted by: paross1
One way...SELECT all your columns
From your_table
WHERE your_engagement_appid = (SELECT MAX (your_id)
From your_table)Phil
Thank you guys. It worked great.
I also tried the front joined query where the... I would have thought that.
Thank you! -
Cursor Oracle return only the last record
I am a newbie in oracle stored proc. I tried to select data using the slider, but it only return last record. The recording must be greater than 1.
CREATE or REPLACE procedure MySchema.Test (myrefcur on sys_refcursor)
Is
Begin
declare
Cursor C1 IS
Select mySerialNum from TableA;
MyRecord C1% rowtype;
Begin
Open C1;
Loop
Fetch C1 into myrecord;
When the output C1% NotFound;
Open for Myrefcur
Select SerialNumB from TableB where SerialNumB = myrecord.mySerialNum;
End loop;
Close C1;
End;
end;
However, it only returns the last record in the list.
Original case *.
The original code is as below:
1st, I'll need to select a list of ImageSerialNum of ImageSerial
* 1 query:
Select A.ImageSerialNum from ImageSerial A, ProductionOrder B, Bom C
Where A.ProductionOrderID = B.ProductionOrderID And B.Assembly_Num = C.Model_Num and
B.Revision = C.Revision And B.EngRevision = C.EngRevision and
C.Bom_ID = passInVariable* and C.FactoryID = "7"
2nd, I'll need to check the process of EACH series with the code below:
* Low code a return process for 1 series only.
Select t.processid, t.processname, t.assembly_num, t.revision, t.engrevision of
(Select p.ProcessID, p.ProcessName, in. Assembly_Num, in. review, in. EngRevision, im.imageserialnum
Process p, Routesequence rs, Imageserial im, ProductionOrder in.
Where im. ImageserialNum = SerialNum* and p.ProcessID = rs. ProcessID
And rs. RouteID = in. RouteID and rs. SequenceID = im. NextRouteSequence
And in. ProductionOrderID = im. ProductionOrderID AND IM. STATUS OF '0'
UNION
SELECT A.REWORKROUTEID AS PROCESSID PROCESSNAME AS B.ROUTENAME, C.ASSEMBLY_NUM, C.REVISION, C.ENGREVISION, a.imageserialnum
OF IMAGESERIAL A, B OF ROAD, PRODUCTIONORDER C
WHERE A.REWORKROUTEID = B.ROUTEID AND A.IMAGESERIALNUM = SerialNum*.
AND A.PRODUCTIONORDERID = C.PRODUCTIONORDERID and a.status = '0') t
After that, I would like to combine the two in 1 stored proc code.in this case, you just want to join the two applications to use in the FROM clause
As I don't have your tables, I created two tables, each representing the results of your queries. Substitute the names of table with your queriesSQL> drop table master 2 / Table dropped. SQL> drop table details 2 / Table dropped. SQL> SQL> create table master 2 (ImageSerialNum varchar2(25)); Table created. SQL> SQL> SQL> insert into master values ('Serial1'); 1 row created. SQL> insert into master values ('Serial2'); 1 row created. SQL> insert into master values ('Serial3'); 1 row created. SQL> insert into master values ('Serial4'); 1 row created. SQL> insert into master values ('Serial5'); 1 row created. SQL> SQL> create table details 2 (ImageSerialNum varchar2(25) 3 ,ProcessID number 4 ,ProcessName varchar2(25) 5 ); Table created. SQL> SQL> insert into details values ('Serial1', 1, 'Process1'); 1 row created. SQL> insert into details values ('Serial3', 3, 'Process3'); 1 row created. SQL> insert into details values ('Serial5', 5, 'Process5'); 1 row created. SQL> SQL> select m.imageserialnum 2 , d.processid 3 , d.processname 4 from master m 5 left outer 6 join details d 7 on (m.imageSerialnum = d.imageserialnum) 8 order by m.imageserialnum 9 / IMAGESERIALNUM PROCESSID PROCESSNAME ------------------------- ---------- ------------------------- Serial1 1 Process1 Serial2 Serial3 3 Process3 Serial4 Serial5 5 Process5
your query will be something like
select m.imageserialnum , d.processid , d.processname from (
) m left outer join ( -
Format the first and the last record of query result
Hello
I have the following query
< tt > select 1 seq, "This is the first record" data from dual union of all the
Select 2, 'Data ' | tNom tab Union all
Select 3, "It was last last record" double
order by 1 < /tt >
When I have the coil this summary to a listfile with col seq noprint option I get:
This is the first record
Data MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
Data MLA_VPD_TABLES
It was the last last record
But I want to:
It's first record MLA_ACCESS_LIST
Data MLA_APPLICATIONS
Data MLA_VPD_PCK
MLA_VPD_TABLES it was save finally last record
I tried with 1 statement with the use of lead and lag, because first and last record stand the other result record. But I get ORA-30484: lack of specification of the window for this function
Is this possible with 1 statement or am I've sentenced to modify the results by myself?
Thank you AukeSelect row_number() case above (tNom control)
When 1 then 'it's the first record
end | tNom |
-case row_number() over (order by desc tNom)
When 1 then 'it was the last record. "
end
tab
order by tNomHTH
Maybe you are looking for
-
No sound when dvd playback pre-recorded on lcd/dvd combi 22DV501B
I hear during playback of the CD or the DVD that I burned myself, but when I try to play any pre-recorded DVDs. Although the image is fine, there is no sound at all. I've looked through all the options settings, but can't see anything that could be t
-
updated to OSX 10.9.8 and cannot open iPhoto
I upgraded OSX 10.7.5 to 10.9.8 and cannot open iPhoto more. I don't have the new photos.
-
Maximum RAM for Pavilion dv7-6107ee, product number LS048EA
Hey there ' All,. I currently have the OEM 8 GB RAM installed. I run VMware Workstation 8 for a laboratory test on my laptop and I would really like to 16 GB of RAM, but it seems that I read a few places that this model is not expandable to 8 GB (wh
-
Aero off when the external monitor is turned by Nvidia ControlPanel
Please see subjectAero works perfectly when the office is developed for the 2nd monitor in normal mode.no work around? Post edited by: mhoffmann Sorry, I forgot to mention my hw: Satellite a100-02 b (geforce go 7600) .. and when I reboot Vista behave
-
I have Windows mail on Vista. My email provider is BT.com mail. I questioned my problems with them, and to be honest I can access my mail via BT.com without problems. If I use Windows mail usually it connects without problems then go download 1Messag