Trying to get newest record using a select statement
Hello everyone.. I'm a bit new at this but I've been teaching myself by trial and error so bear with me.
Using a 'DEDUCTION' table for this example, I am trying to get it to resolve the record that is most current. Since each employee record could have changes, the table could have multiple entries/deductions of which only one is the most current.
Ok, so medical deductions are like DEDUCTIONS 700-715 while dental deductions are 730-737. Initially, I was trying to figure out how to pull the deductions based on an employee and have it compare which is newer and report the newest one for each medical and then the dental deduction. If there is not a type of deduction for someone, it should report zero like a NVL I think. See example:
EMP_ID DEDUCTIONS EFF_DATE AMT
1 710 2000/12/01 85.39
1 735 2000/12/01 8.31
9 701 2001/08/29 12
9 707 2000/12/01 12
9 730 2000/12/01 .23
10 700 2001/02/25 .46
10 730 2001/02/25 .23
The record that stands out in this example is employee #9 with two medical deduction, one that supersedes the other - 701 and 707. Because 701 is newer it should ignore the 707 deduction.
Any ideas? Thank you!
ken
Here are a couple of methods. The second one should run faster, but requires Oracle 8i.
SQL> SELECT emp_id, deductions, eff_date, amt,
2 'MEDICAL' AS type
3 FROM deduction
4 WHERE (emp_id, eff_date) IN
5 (SELECT emp_id, MAX (eff_date)
6 FROM deduction
7 WHERE deductions BETWEEN 700 AND 715
8 GROUP BY emp_id)
9 AND deductions BETWEEN 700 AND 715
10 UNION
11 SELECT emp_id, deductions, eff_date, amt,
12 'DENTAL' AS type
13 FROM deduction
14 WHERE (emp_id, eff_date) IN
15 (SELECT emp_id, MAX (eff_date)
16 FROM deduction
17 WHERE deductions BETWEEN 730 AND 737
18 GROUP BY emp_id)
19 AND deductions BETWEEN 730 AND 737
20 ORDER BY emp_id, deductions
21 /
EMP_ID DEDUCTIONS EFF_DATE AMT TYPE
1 710 2000/12/01 85.39 MEDICAL
1 735 2000/12/01 8.31 DENTAL
9 701 2001/08/29 12 MEDICAL
9 730 2000/12/01 .23 DENTAL
10 700 2001/02/25 .46 MEDICAL
10 730 2001/02/25 .23 DENTAL
6 rows selected.
SQL> SELECT emp_id, deductions, eff_date, amt,
2 'MEDICAL' AS type
3 FROM (SELECT emp_id, deductions, eff_date, amt,
4 RANK () OVER
5 (PARTITION BY emp_id
6 ORDER BY eff_date DESC) AS rk
7 FROM deduction
8 WHERE deductions BETWEEN 700 AND 715)
9 WHERE rk = 1
10 UNION
11 SELECT emp_id, deductions, eff_date, amt,
12 'DENTAL' AS type
13 FROM (SELECT emp_id, deductions, eff_date, amt,
14 RANK () OVER
15 (PARTITION BY emp_id
16 ORDER BY eff_date DESC) AS rk
17 FROM deduction
18 WHERE deductions BETWEEN 730 AND 737)
19 WHERE rk = 1
20 ORDER BY emp_id, deductions
21 /
EMP_ID DEDUCTIONS EFF_DATE AMT TYPE
1 710 2000/12/01 85.39 MEDICAL
1 735 2000/12/01 8.31 DENTAL
9 701 2001/08/29 12 MEDICAL
9 730 2000/12/01 .23 DENTAL
10 700 2001/02/25 .46 MEDICAL
10 730 2001/02/25 .23 DENTAL
6 rows selected.
Similar Messages
-
How to Get Top 10 records using SQL select statement.
:-) Hiee E'body,
I want to generate a sql report in which I only want the top 10 records based on the numeric value of a column.
For Example,
To generate a Location Wise, Employee Wise Years of Service Report.
Here I need the Top 10 Employees according to their No. of Years of Service for all the existing locations using a single query.
eg.
Location Emp No. YOS
India - 22 30
212 28
819 24 ...
US 123 40
312 33
90 33
144 30 ...
UK 77 20
79 20
331 18
109 16 ...
Every Location should display their respective Top 10 Employees
regarding their No. of Years of Service.
Please let me the know the solution to this.
Have a nice day.
Thanking You,
Vivek Kapoor.For example if the table contained (India rows only shown) :
India 202 30
India 212 28
India 819 24
India 820 24
India 900 20
India 920 18
India 922 17
India 925 16
India 926 15
India 927 14
India 928 13
India 929 13
India 930 12
do you want to see
India 202 30
India 212 28
India 819 24
India 820 24
India 900 20
India 920 18
India 922 17
India 925 16
India 926 15
India 927 14
or
India 202 30
India 212 28
India 819 24
India 820 24
India 900 20
India 920 18
India 922 17
India 925 16
India 926 15
India 927 14
India 928 13
India 929 13
Also if the India rows were
India 202 30
India 212 30
India 819 30
India 820 30
India 900 30
India 920 30
India 922 30
India 925 30
India 926 30
India 927 30
India 928 30
India 929 30
do you want to see
India 202 30
India 212 30
India 819 30
India 820 30
India 900 30
India 920 30
India 922 30
India 925 30
India 926 30
India 927 30
or
India 202 30
India 212 30
India 819 30
India 820 30
India 900 30
India 920 30
India 922 30
India 925 30
India 926 30
India 927 30
India 928 30
India 929 30
Please clarify.
Thanks,
Partha -
How to get multiple records using fn-bea:execute-sql()
Hi,
I created Proxy service(ALSB3.0) to get records from DB table. I have used Xquery function(fn-bea:execute-sql()). Using simple SQL query I got single record, but my table having multiple records. Please suggest how to get multiple records using fn-bea:execute-sql() and how to assign them in ALSB variable.
Regards,
Nagaraju
Edited by: user10373980 on Sep 29, 2008 6:11 AMHi,
Am facing the same issue stated above that I couldnt get all the records in the table that am querying in the Proxyservice.
For example:
fn-bea:execute-sql('EsbDataSource', 'student', 'select Name from StudentList' ) is the query that am using to fetch the records from the table called StudentList which contains more than one records like
Id Name
01 XXX
02 YYY
03 ZZZ
I tried to assign the result of the above query in a variable and while trying to log the variable, I can see the below
<student>
<Name>XXX</Name>
</student>
I want to have all the records from my table in xml format but it's not coming up. I get the value only from the first row of my table.
Please suggest.
regards,
Venkat -
How to get the value from a function using a select statement
I have a function(user defined not built in) that returns multiple values(like an array). My question is how do i get those values in a select statement. when i tried to retrieve it,
select pack.my_members from dual;
i am getting an error
ORA-00902: invalid datatype
I am sure this must be a syntax error with the select statement
The following is the function that give the array of data
package pack
package spec
Type my_table is table of varchar2(25);
function the_members
return pack.my_table;
pakcage body
function the_members return pack.my_table
Remarks: This function returns a table containing names of the
members
is
tm pack.my_table:= pack.my_table('first member','second member','third member','fourth member');
begin
return tm;
end the_members;Check this example on Pipelinedfunction
-
I am trying to get authorisation to use Adobe digital edition, but my book's vendor is not on the list, and hence the password not accepted.
Numbers documents from iOS need Numbers 3.2 on a Mac to open. And Numbers 3.2 requires Mavericks. If you are using Mavericks you can get Numbers 3.2 from the Mac App Store. It will be free IF you have Numbers 2 (iWork '09) installed. Otherwise you must buy it.
Your other option is to send the Numbers file as an Excel file via e-mail to yourself to open with an earlier version of Numbers. -
Getting socket error while trying to get oracle connection using JDBC
hi,
I am getting following socket read error while trying to get database connection using JDBC. This happening with jdk1.5.0_12 version with Oracle 9i
following is the stacktrace...
Thread t@92: (state = IN_NATIVE)
- java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[], int, int, int) @bci=0 (Compiled frame; information may be imprecise)
- java.net.SocketInputStream.read(byte[], int, int) @bci=84, line=129 (Compiled frame)
- oracle.net.ns.Packet.receive() @bci=31 (Compiled frame)
- oracle.net.ns.DataPacket.receive() @bci=1 (Interpreted frame)
- oracle.net.ns.NetInputStream.getNextPacket() @bci=48 (Compiled frame)
- oracle.jdbc.driver.T4CMAREngine.unmarshalSB1() @bci=1, line=1070 (Compiled frame)
- oracle.jdbc.driver.T4CStatement.doOall8(boolean, boolean, boolean, boolean) @bci=617, line=207 (Compiled frame)
- oracle.jdbc.driver.T4CStatement.executeForDescribe() @bci=39, line=790 (Compiled frame)
- oracle.jdbc.driver.OracleStatement.executeMaybeDescribe() @bci=106, line=1039 (Interpreted frame)
- oracle.jdbc.driver.T4CStatement.executeMaybeDescribe() @bci=11, line=830 (Interpreted frame)
- oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout() @bci=128, line=1132 (Interpreted frame)
- oracle.jdbc.driver.OracleStatement.executeQuery(java.lang.String) @bci=76, line=1272 (Interpreted frame)
any help would appreciated. thanks in advanceI do not have exact exception message.
additionally, i have got following the tomcat log file:
INFO - Resource pool cleanup thread just woke up.
Nov 1, 2008 3:41:52 AM org.apache.tomcat.util.threads.ThreadPool logFull
SEVERE: All threads (100) are currently busy, waiting. Increase maxThreads (100) or check the servlet status
INFO - Resource pool cleanup thread just woke up.
thanks in advance -
Getting exception when trying to get taskdetails url using BPM worklist api
Getting exception when trying to get taskdetails url using BPM worklist api method :
String url = WorklistUtil.getTaskDisplayURL(
wfSvcClient,
ctx,
task,
null,
"worklist",
parameters);
Jul 21, 2011 11:24:40 AM oracle.bpel.services.common.ServicesLogger __log
WARNING: <oracle.bpel.services.workflow.client.worklist.util.TaskFlowPropsUtil.getServerPropertiesFromMbean()> Exception while loading install config file in standalone Error : javax.management.InstanceNotFoundException: com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean: com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean
oracle.fabric.common.FabricException: javax.management.InstanceNotFoundException: com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean: com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean
at oracle.soa.common.util.PlatformUtils.getServerInfo(PlatformUtils.java:184)
at oracle.bpel.services.workflow.client.worklist.util.TaskFlowPropsUtil.getServerPropertiesFromMbean(TaskFlowPropsUtil.java:319)
at oracle.bpel.services.workflow.client.worklist.util.TaskFlowPropsUtil.getServerInfoForWeblogicServer(TaskFlowPropsUtil.java:491)
at oracle.bpel.services.workflow.client.worklist.util.TaskFlowPropsUtil.getServerInfo(TaskFlowPropsUtil.java:363)
at oracle.bpel.services.workflow.worklist.api.util.WorklistUtil.getDefaultURLPrefix(WorklistUtil.java:264)
at oracle.bpel.services.workflow.worklist.api.util.WorklistUtil.getTaskDisplayURL(WorklistUtil.java:353)
at oracle.bpel.services.workflow.worklist.api.util.WorklistUtil.getTaskDisplayURL(WorklistUtil.java:293)
at com.test.WorflowServiceClient.main(WorflowServiceClient.java:198)
Caused by: javax.management.InstanceNotFoundException: com.bea:Name=RuntimeService,Type=weblogic.management.mbeanservers.runtime.RuntimeServiceMBean
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(DefaultMBeanServerInterceptor.java:1094)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(DefaultMBeanServerInterceptor.java:662)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(JmxMBeanServer.java:638)
at oracle.as.jmx.framework.config.session.ConfigurationMBeanServerImpl.getAttribute(ConfigurationMBeanServerImpl.java:210)
at oracle.soa.common.util.PlatformUtils.getServerInfo(PlatformUtils.java:78)
... 7 more
Caught workflow exception: null
Process exited with exit code 0.
Can anyone please help meActually i'm using Jdeveloper 11.1.1.4 and our requirement is to show list of BPM worklist tasks for the logged in user on the first page and onclick of each task task details page should be opened. I can use Webcenter PS3 worklist taskflow. But i'm not able to customize that taskflow. So, i'm going for Worklist client api.
I'm able to retrive the taskId,task title and few other details like task payload. But i don't know why the below method is giving exception.
String url =
WorklistUtil.getTaskDisplayURL(wfSvcClient,
ctx, task, null,
"worklist", parameters);
And i observed that you have also used the same code for getting Taskdetails url. And one more thing is i'm trying to access BPM worklist which is installed on remote machine.
Can you tell me what could be the reason for the exception? -
Restricting records in the select statement
Hi,
I have one requirement where in i need to restrict my select statement to get only 250 records in the output table.
Here are the select statements i am using....
SELECT a~ebeln
a~lifnr
a~ekgrp
b~werks
b~matnr
FROM ekko AS a INNER JOIN ekpo AS b
ON aebeln = bebeln
INTO TABLE i_ekko
WHERE a~ebeln IN r_ebeln AND
a~lifnr IN r_lifnr AND
a~ekgrp IN r_ekgrp AND
b~werks IN r_ewerk AND
b~matnr IN r_matnr AND
a~bstyp = 'F'.
IF NOT i_ekko[] IS INITIAL.
Select Vendor name
SELECT lifnr
name1
FROM lfa1
INTO TABLE i_lfa1
FOR ALL ENTRIES IN i_ekko
WHERE lifnr = i_ekko-lifnr.
Here if i restrict the first select statement to get only 250 records then i am not getting the desired record in the second select statement.
Could anyone let me know how to write the select statement.
Regards,
Rameshrestric the first select using up to 250.
sort the i_ekko by vendor name.
ex: sort i_ekko by lifnr.
use second select statement here. -
How to use the select statement in for loop
Hi All,
my question is can we use select statement in for loop like as follows .
for key in select key from one_table.
when i am using this am getting an error like Found select invalid i identifier
how to make use of select statement in for loop
please suggest me .
Thanks
SreeSQL>set serveroutput on;
SQL> DECLARE
BEGIN
FOR Cur_Rec IN (SELECT dname FROM dept) LOOP
DBMS_OUTPUT.PUT_LINE(Cur_Rec.dname);
END LOOP;
END;
SQL>
ACCOUNTING
RESEARCH
SALES
OPERATIONSAs per your requirement always filter the Query beforehand
Like
FOR Cur_Rec IN (SELECT key FROM <table> WHERE key=1) LOOP
END LOOP;Edited by: Lokanath Giri on १ दिसंबर, २०११ ३:५६ अपराह्न -
Create a view using a select statement
Hi
I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
I am new to oracle so any help will do.
ThanksHi
I need to create a view using a select statement to view details from 2 different tables which will only show data where the holidays commence after june.
I am new to oracle so any help will do.
Thanks -
How to join THREE different tables into internal table using one select statement .
How to join THREE different tables into internal table using one select statement .
Hi experts,
I would like to request your guidance in solving the problem of joining the data from three different database tables into one internal table
Scenario:
Database tables:
SPFLI
SFLIGHT
SBOOK.
Table Fields:
SPFLI - CARRID CONNID COUNTRYFR CITYFRM COUNTRYTO CITYTO
SFLIGHT - CARRID CONNID FLDATE SEATSMAX SEATSOCC SEATSMAX_C
SEATSOCC_C SEATSMAX_F SEATSOCC_F
SBOOK - CARRID CONNID CLASS
MY INTERNAL TABLE IS IT_XX.
Your help much appreciated.
Thanks in advance.
Pawan.Hi Pawan,
please check below codes. hope it can help you.
TYPES: BEGIN OF ty_xx,
carrid TYPE spfli-carrid ,
connid TYPE spfli-connid ,
countryfr TYPE spfli-countryfr,
cityfrom TYPE spfli-cityfrom ,
countryto TYPE spfli-countryto,
cityto TYPE spfli-cityto ,
fldate TYPE sflight-fldate ,
seatsmax TYPE sflight-seatsmax ,
seatsocc TYPE sflight-seatsocc ,
seatsmax_b TYPE sflight-seatsmax_b,
seatsocc_b TYPE sflight-seatsocc_b,
seatsmax_f TYPE sflight-seatsmax_f,
seatsocc_f TYPE sflight-seatsocc_f,
class TYPE sbook-class,
END OF ty_xx,
t_xx TYPE STANDARD TABLE OF ty_xx.
DATA: it_xx TYPE t_xx.
SELECT spfli~carrid
spfli~connid
spfli~countryfr
spfli~cityfrom
spfli~countryto
spfli~cityto
sflight~fldate
sflight~seatsmax
sflight~seatsocc
sflight~seatsmax_b
sflight~seatsocc_b
sflight~seatsmax_f
sflight~seatsocc_f
sbook~class
INTO TABLE it_xx
FROM spfli INNER JOIN sflight
ON spfli~carrid = sflight~carrid
AND spfli~connid = sflight~connid
INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid.
Thanks,
Yawa -
Getting Error while trying to enter multiple records using PA70
Hi all,
While trying to enter multiple records for a custom infotype using transaction PA70,
the system asked to provide details of the custom infotype in T588Q and T588r tables after giving the details i'm able to enter into the custom infotype screen but the Personnel number is defaultly taken as
zero and im not able to change the value and if i click save after entering the other details it is throwing an error telling that Infotype doesnt exist.
Please Help..
Thanks & Regards,
Kumar MadduruHi,
Let us know the detailed error text. Probably you haven't included the infotype to maintain in Fast Entry or doesn't have the authorization.
Good Luck
Om -
Get all records in multi selected master child tables
Hi,
I am using JDeveloper 11.1.1.4 version and using ADF-BC in my project.
I have a simple master child[one to many] relationship in my project.
In my view page,I display this master child [Ex: EmpVo1--->DeptVo2] as tables.
I have multi-slection enabled for master table.
My requirement is that,on multi selecting the rows in master tables,I want to get all the child records in my backing bean.
that is if a master row has 3 child records and another master row has 4 child records and on multiple selection of these two records in master table,I should get all the child records in my backing bean.
I need this to implement cascade delete functionality.
Following is sample piece of code
1) called on selecting the rows in master table
public void onRSCGrpSelect(SelectionEvent selectionEvent) {
// Add event code here...
ADFUtil.invokeEL("#{bindings.RscGroupVO1.collectionModel.makeCurrent}",
new Class[] { SelectionEvent.class },
new Object[] { selectionEvent });
RowKeySet rowKeySet = (RowKeySet)tblRSCGrp.getSelectedRowKeys();
CollectionModel cm = (CollectionModel)tblRSCGrp.getValue();
for (Object facesTreeRowKey : rowKeySet) {
cm.setRowKey(facesTreeRowKey);
JUCtrlHierNodeBinding rowData =
(JUCtrlHierNodeBinding)cm.getRowData();
Row row = rowData.getRow();
System.out.println("\n" +
row.getAttribute(0) + " :: " + row.getAttribute(1) +
" :: " + row.getAttribute(2));
System.out.println("Displaying Child Records");
displayChildRecords(row.getAttribute(0));
2. private void displayChildRecords(Object rscGrp) {
ViewObject rscMapVo = getRscMapViewObj();
RowSetIterator rsI = rscMapVo.createRowSetIterator(null);
while (rsI.hasNext()) {
Row row = rsI.next();
System.out.println("\n" +
row.getAttribute(0) + " :: " + row.getAttribute(1) +
" :: " + row.getAttribute(2));
rsI.closeRowSetIterator();
But the problem is that ,it is always giving me the last selected rows child record details
Please suggest the error I am doing.
Thanks,
PraveenYour problem is that you use makecurrent, which should not be used on a multi select table. Next if you have master detail relationship you should have a view link between them. In this case you can expose a method in you master to get the related child row. No need to get the VO itself as you can use the child iterator accessors to get the child record.
public void onRSCGrpSelect(SelectionEvent selectionEvent) {
// Add event code here...
RowKeySet rowKeySet = (RowKeySet)tblRSCGrp.getSelectedRowKeys();
CollectionModel cm = (CollectionModel)tblRSCGrp.getValue();
for (Object facesTreeRowKey : rowKeySet) {
cm.setRowKey(facesTreeRowKey);
JUCtrlHierNodeBinding rowData =
(JUCtrlHierNodeBinding)cm.getRowData();
Row row = rowData.getRow();
//cast to the right row class
EmpEmpVoRow empRow = (EmpEmpVoRow) row;
// now you cann access the child row iterator
RowSetIterator it = empRow.getDepVO();
//now you cna iterate over the child rows
System.out.println("\n" +
row.getAttribute(0) + " :: " + row.getAttribute(1) +
" :: " + row.getAttribute(2));
System.out.println("Displaying Child Records");
//use hte child rows here
}Not sure if the code compiles out of the box (doing this on the train :-)
Timo -
invoke-webrequest content returning only 2000 records though it has around 4000 records in web api.
The same url if I give in excel oData Data feed I am getting all the records.
See the below script
Script:
$QueryResult= (Invoke-WebRequest -Uri $ODataURI -UseDefaultCredentials)
[xml]$xmlResult=$QueryResult.content
foreach($obj in $xmlResult.feed.entry.content.properties)
$Name=$obj.Name;
$IsAvail=$obj.isAvail.'#text';
$PGroup=$obj.PGroup
I am exporting the above result as a CSV file and my CSV file contains only 2000 records.
But, $xmlResult.feed.Count --> it Shows 4000 Records.
The same Odata url if I give in excel oData Data feed I am getting all the 4000 records.
So Please help me how can I get all the records using power shell.
Thanks
A Pathfinder..
JoSwa
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful"
Best Online JournalHi Jo Swa(K.P.Elayaraja)-MCP,
Would you please also post code which is used to export the records?
In addition, to use the cmdlet invoke-RestMethod to work on ODate feeds, please refer to this article:
Interacting with TechEd NA 2012 Schedule using PowerShell v3
I hope this helps. -
Trying to get t my email, this comes up: We are sorry, but you will need to enable cookies and Javascript to use your Username with this site.
How do I do this?
George Szanto<br />
[email protected]see similar question answered at https://support.mozilla.com/questions/836913
To be notified of updates to a question whether it is your problem or not simply click on the "Get email notifications" and follow directed choice. Only the original poster can mark as solved, so there should be a slight difference in choice as an original poster and where you latch onto another question. The notifications only apply to the specific question where entered.
Maybe you are looking for
-
Oracle 8.1.5.0.1 Patch Relink Problem
When applying the patch I got the following error: /usr/bin/ld: cannot open -lordsdo8: No such file or directory collect2: ld returned 1 exit status gmake: *** [usr/local/ora815/rdbms/lib/oracle] Error 1 Which I have tracked down to this line of the
-
[JS CS3] Modify geometricBounds of Inline Frames in Overset Text
Hello, I have the following setting: I recieve a XML file , which contains <image href="..."> tags. InDesign automatically inserts the correct images as an inline frame. The layout column are too small for the large images, so when placing the XML in
-
Weblogic.jar for Weblogic 4.5.1
I'm trying to upgrade the Weblogic JSP Compiler optional Ant task so that it will work with newer version of Weblogic JSP Compiler. I got it to work for 6.1, 7.0 and 8.1. The current released version of Ant supports only Weblogic JSP compiler version
-
Conditions using subquery in EUL
Hi, New to Discoverer - can anyone please clarify the following. 1) Is it possible to have a condition created in EUL using correlated subquery? 2) Is it true that in Discoverer Plus 10g, one cannot create a condition with subquery and can do it only
-
Delayed iMessages to iPhone despite coming through on Ipad
Very often I will get an iMessage that comes through on my iPad (iPad 2), but it can take sometimes up to 15 minutes for it to come through on my iPhone (4s). I can even go back and forth a few times via my iPad with the person who sent the original