Query to find the latest record with respect to the current status
Dear gurus
I have the following data in a table
Customernum
bkcode
reqtdate
Prevstat
currstat
The data will be like this
CustomerNum bkcode reqdate prevstat currstat
5900 1 03-Aug-12 0 1
5900 1 06-Aug-12 1 0
5900 5 22-Jun-12 0 1
If a customer has an issue to solved, a record is added with bkcode , register date and currstat will be 1
If the issue is resolved for the bookingcode,a new record is added, the currentstatus will become 0. and prev stat will show 1. Row no 1 and 2 reflects this case
If this table is queried for finding the unresolved issues. the output should be only the Last row of the above example. since issue with bookingcode 1 has been resolved
I have trying hard to get this thing confused what to use Lead or Max
Kindly guide me
Hi,
one way here:
WITH mytable(CustomerNum, bkcode, reqdate, prevstat, currstat)
AS
SELECT 5900, 1, TO_DATE('03-Aug-12', 'DD-Mon-YY'), 0, 1 FROM DUAL UNION ALL
SELECT 5900, 1, TO_DATE('06-Aug-12', 'DD-Mon-YY'), 1, 0 FROM DUAL UNION ALL
SELECT 5900, 5, TO_DATE('22-Jun-12', 'DD-Mon-YY'), 0, 1 FROM DUAL
SELECT CustomerNum, bkcode, reqdate, prevstat, currstat
FROM (SELECT a.*
, ROW_NUMBER() OVER (PARTITION BY CustomerNum, bkcode
ORDER BY reqdate DESC) AS rn
FROM mytable a
WHERE rn=1
AND currstat=1;
CUSTOMERNUM BKCODE REQDATE PREVSTAT CURRSTAT
5900 5 22-JUN-12 0 1Regards.
Al
Edited by: Alberto Faenza on Dec 18, 2012 5:23 PM
Changed again!! Previous logic was wrong
Similar Messages
-
Query to find 10 latest records
hi all,
i have 100 records with following attributes.
username
mobile no
date
i want to select 10 latest rocords for a perticular mobile no(based on date attribute).
regards,
uttamHi Mohan,
I would use the same analytic function to get the records. However, I will have to modify the expression to get the records starting from the latest date as posted by Uttam. I just added the option DESC to start from the latest record and run down to the earliest.
select * from(
select username, mobile_no, date,
rank() over(partition by mobile_no order by date DESC) rn
from tabl1)
WHERE rn<=10; -
Hi All,
I have created a form with 5 blocks (namely ENQACMHDR, ENQACMDTL, ENQACEHDR, ENQACEDTL, ENQACSPEC), where i have 8 push buttons (namely ENTER_QUERY, EXEC_QUERY, CLEAR, FIRST, NEXT, PREVIOUS, LAST & EXIT).
This form is created just for viewing purpose only. So after I execute, all the blocks have been blocked against insert & update.
I query on 2 fields that is 'ENQNO' and 'RATNG' (Both the fields belong to the block ENQACMDTL).
When I click on 'EXEC_QUERY' directly, all the data of all the years populates.
But the user wanted the data to be populated from only the present year and the previous year.
So , on 'WHERE Clause' of the property_palette of 'ENQACMDTL' block , I put in the following condition:
SUBSTR(ENQACMDTL.ENQNO, 1,4)=TO_CHAR( ADD_MONTHS(SYSDATE,-12) , 'YYYY') OR SUBSTR(ENQACMDTL.ENQNO, 1,4)=TO_CHAR(SYSDATE, 'YYYY')
PROPERTY PALETTE (ENQACMDTL block)
WHERE Clause
SUBSTR(ENQACMDTL.ENQNO, 1,4)=TO_CHAR( ADD_MONTHS(SYSDATE,-12) , 'YYYY') OR SUBSTR(ENQACMDTL.ENQNO, 1,4)=TO_CHAR(SYSDATE, 'YYYY')
Now the data of only the present year and the previous year is being populated. Its ok with the field of 'ENQNO'.
The problem is when i query on field 'RATNG' . 'RATNG' is a Text_item with Number of Items displayed=5. (5 rows)
The following are 2 columns of a Table (Name=ENQACMDTL) in Database.
ENQNO
RATNG
2013900054
500KC2
2013900047
800KC4
2013520018
750KC6
2012900037
1000KC2
2012520109
500KC2
2012140019
750KC6
2011540036
500KC2
2011100030
1000KC2
2006100007
90KD8
2006750014
750KC6
2006900072
500KC2
The first 4 numbers of 'ENQNO' denotes the year. There are more than a lakhs of records.
So when i query on the field 'RATNG',
Example:For RATNG=500KC2;
I click on ENTER_QUERY, On the field of 'RATNG' , i put in the value 500KC2 and click on EXEC_QUERY; Details with respect to 500KC2 is displayed as well as all the other unwanted RATNG like 750KC6, 1000KC2 (which belongs to the ENQNO of the present year and the previous year) also gets displayed.
I want details of only RATNG (500KC2) to be displayed, but only of the present year and the previous year, that is 2013900054, 2012520109 (ENQNO).
Other than 500KC2 RATNG, no other RATNG must be displayed.
The RATNG=500KC2 is also present for ENQNO=2011540036 , 2006900072. But I dont want these to be displayed.
I want only the data or details of the present year and the previous year to be displayed or populated with respect to the given RATNG.
Can You Help me or tell me what do i do for this?
Hope I'm clear with my question!!
If my question is not clear, let me know plz.
Thank You.
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
Oracle forms 6i.On key-exeqry you have to program. Delete all other trigger codings for checking your condition.
It dint work on key-exeqry.
I tried key-exeqry on form trigger, block (enqacmdtl) and also on field(:enqacmdtl.enqno) , but none of them worked.
It did not display the message.
I have a 'PUSH-BUTTON:EXEC_QUERY.
For EXEC_QUERY, Trigger : WHEN_BUTTON_PRESSED;
I added the following code:
if to_number(substr(:enqacmdtl.enqno,1,4))<to_number(to_char(add_months(sysdate,-12),'YYYY')) then
message('The Rating is not present for the present year and the previous year');message(' ',no_acknowledge);
raise form_trigger_failure;
else
execute_query;
end if;
It is working fine and the message is being displayed.
But again I have a new problem and that is;
On the field :enqacmdtl.enqno, when i enter the '2013%' and press 'EXEC_QUERY', it works fine.
but when i enter '2006%' and press 'EXEC_QUERY', it shows the following error
FRM-50016: Legal characters are 0-9 - +E. It does not display the message also.
but when i enter the complete number, '2006580002', then it works fine , that is it displays the message (The Rating is not present for the present year and the previous year).
The problem is because of '%', only when i put in the restricted data (which does not satisfy where condition).
How do i solve this?
Thank You Priyasagi. -
Summing on the latest record with MDX
I'm trying use MDX to sum up the most recent [Employee Compensation].[Employee Scheduled Hours] member for each [Employee].[Employee] but in the context of the the current query. Employee Compensation is a type II dimension, and an Employee can change scheduled
hours from week to week (but we just want to see the most recent). How can I roll this up properly in a calculated member? Sample data is like:
EmployeeKey
EmployeeCompensationKey
DateKey
100
40
20140101
100
20
20140107
200
40
20140101
200
30
20140107
In this case, if I roll up 2014 January, I would expect to see a sum of (20 + 30) =
60 for the Employee Scheduled Hours. Please note, the EmployeeCompensationKey in the sample table is actually a surrogate key to the Employee Compensation dimension with the attribute of Employee Scheduled Hours. I've just put the member values
here for simplification.
I'm using the following MDX query, but this only works for certain scenarios. How would I set up this? I have a feeling the set I'm returning from TAIL function is probably the issue.
SUM(
EXISTING(DESCENDANTS([Employee].[Employee].[All],,AFTER)),
STRTOVALUE(
TAIL(
NONEMPTY(
[Employee Compensation].[Scheduled Hours].[Scheduled Hours],
{[Measures].[Headcount]}),
1).Item(0).NAMEDimensionality for the LASTNONEMPTY function is over the date/time dimension, so if an employee got several checks in the same day, it would sum up the measure for that employee for that day.
I'd rather not have to create a new fact measure, but I suppose I'll look into using a windowing function or another alternative to populate the scheduled hours on only one of those one-to-many records at the same time.
One last idea is that, I know I can pull the tuple of last scheduled hour per each employees as so:
DESCENDANTS([Employee].[Employee].[All],,AFTER)
TAIL(TOPCOUNT(DESCENDANTS([Employee Compensation].[Scheduled Hours].[All],,AFTER),1,[Measures].[Headcount]),1).item(0)
But I don't know how to extract from this tuple, just the set of employee scheduled hours portion... -
Hi ,
How to find out the latest Record in per_all_people_f and per_all_assignments_f
Requirement : Need to find out the latest record in per_all_people_f and per_all_assignments_f to update the attribute column with pre defined value . Its not possible to track only with person_id / assignment_id and effective end date
SELECT pp_id
FROM (SELECT app.person_id pp_id,
asf.*
FROM apps.per_all_people_f app,
apps.per_all_assignments_f asf
WHERE --app.person_id=123568 and
asf.person_id = app.person_id AND
app.effective_end_date = to_date('31-dec-4712') AND
asf.effective_end_date = to_date('31-dec-4712')
GROUP BY app.person_id)
HAVING COUNT(pp_id) > 1
GROUP BY pp_id
This query also returns more than 1 value for person_id .
It would be great if you put comment on this .. Thanks in advance ,
AryaI am getting more records with asf.primary_flag='Y' . If you give ur mail id , i will send the sample data
ASSIGNMENT_ID EFFECTIVE_START_DATE EFFECTIVE_END_DATE BUSINESS_GROUP_ID RECRUITER_ID GRADE_ID POSITION_ID JOB_ID ASSIGNMENT_STATUS_TYPE_ID PAYROLL_ID LOCATION_ID PERSON_REFERRED_BY_ID SUPERVISOR_ID SPECIAL_CEILING_STEP_ID PERSON_ID RECRUITMENT_ACTIVITY_ID SOURCE_ORGANIZATION_ID ORGANIZATION_ID PEOPLE_GROUP_ID SOFT_CODING_KEYFLEX_ID VACANCY_ID PAY_BASIS_ID ASSIGNMENT_SEQUENCE ASSIGNMENT_TYPE PRIMARY_FLAG APPLICATION_ID ASSIGNMENT_NUMBER CHANGE_REASON COMMENT_ID DATE_PROBATION_END DEFAULT_CODE_COMB_ID EMPLOYMENT_CATEGORY FREQUENCY INTERNAL_ADDRESS_LINE MANAGER_FLAG NORMAL_HOURS PERF_REVIEW_PERIOD PERF_REVIEW_PERIOD_FREQUENCY PERIOD_OF_SERVICE_ID PROBATION_PERIOD PROBATION_UNIT SAL_REVIEW_PERIOD SAL_REVIEW_PERIOD_FREQUENCY SET_OF_BOOKS_ID SOURCE_TYPE TIME_NORMAL_FINISH TIME_NORMAL_START BARGAINING_UNIT_CODE LABOUR_UNION_MEMBER_FLAG HOURLY_SALARIED_CODE REQUEST_ID PROGRAM_APPLICATION_ID PROGRAM_ID PROGRAM_UPDATE_DATE ASS_ATTRIBUTE_CATEGORY ASS_ATTRIBUTE1 ASS_ATTRIBUTE2 ASS_ATTRIBUTE3 ASS_ATTRIBUTE4 ASS_ATTRIBUTE5 ASS_ATTRIBUTE6 ASS_ATTRIBUTE7 ASS_ATTRIBUTE8 ASS_ATTRIBUTE9 ASS_ATTRIBUTE10 ASS_ATTRIBUTE11 ASS_ATTRIBUTE12 ASS_ATTRIBUTE13 ASS_ATTRIBUTE14 ASS_ATTRIBUTE15 ASS_ATTRIBUTE16 ASS_ATTRIBUTE17 ASS_ATTRIBUTE18 ASS_ATTRIBUTE19 ASS_ATTRIBUTE20 ASS_ATTRIBUTE21 ASS_ATTRIBUTE22 ASS_ATTRIBUTE23 ASS_ATTRIBUTE24 ASS_ATTRIBUTE25 ASS_ATTRIBUTE26 ASS_ATTRIBUTE27 ASS_ATTRIBUTE28 ASS_ATTRIBUTE29 ASS_ATTRIBUTE30 LAST_UPDATE_DATE LAST_UPDATED_BY LAST_UPDATE_LOGIN CREATED_BY CREATION_DATE TITLE OBJECT_VERSION_NUMBER
931510 7-Nov-08 31-Dec-12 122 (null) (null) (null) 3978 1 (null) 14402 (null) 220150 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 2 E Y (null) 100035417-2 (null) (null) (null) 45948739 (null) (null) (null) (null) (null) (null) (null) 868007 (null) (null) (null) (null) 449 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null)
797386 26-Aug-08 26-Aug-08 122 (null) (null) (null) 3980 3 (null) 14402 (null) 218925 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 1 E Y (null) 100035417 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) 740071 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null)
916076 26-Aug-08 31-Dec-12 122 (null) (null) (null) 3980 1 4 14402 (null) 218925 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 1 B Y (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null)
797386 25-Feb-08 25-Aug-08 122 (null) (null) (null) 3980 1 (null) 14402 (null) 218925 (null) 734956 (null) (null) 476 (null) (null) (null) (null) 1 E Y (null) 100035417 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) 740071 (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) (null) -
Select the one record with the latest record
I have the following table called tblSales:
SKU TransDate Color
=== ====== ====
123 1/1/2015 Red
123 1/2/2015 Red
123 1/5/2015 Red
123 1/1/2015 White
123 1/2/2015 White
123 1/3/2015 White
123 1/1/2015 Blue
123 1/2/2015 Blue
123 1/5/2015 Blue
I need to create a query along the lines "SELECT the latest record FROM tblSales WHERE Color = 'White''
In this example, the record dated 1/3/2015 would be the result. I know that MAX(TransDate) is used here, but not sure how.
Thanks.
KenKarl,
I had already tried that. It returns all 3 records having SKU = 123 and Color = White.
Worst case scenario is I can always search for White 123s using a query with TransDate DESC and then get the first record. I was just hoping for something a bit more elegant.
Thanks for your help though.
Ken -
Query to find no of peoples with the same age(using distinct)
query to find no of peoples with the same age(using distinct)
Edited by: swordfish3 on Mar 7, 2009 9:24 PMit would be helpful if you posted some proper sample data with proper expected results.
The easier you make it for us to help you, the more likely you will get helped. -
Formula to get the latest record
Hi,
I looking to have only the last record logged displayed on my report, can any one help me with the formula ?
Sorry,
Actually to be more precise I'm looking to the latest record for each equipment (where there are many records for the equipment during the day).
Many thanks,
Andreia
Edited by: andreia silva on Dec 22, 2009 3:12 PM
Edited by: andreia silva on Dec 22, 2009 3:15 PMHi,
You could use a SQL Expression field. The following example uses the Northwind database (SQL Server) as an example.
Type the following query in the SQL Expression editor
(SELECT MAX("Orders"."OrderDate")
FROM Orders
WHERE CustomerID = Customers.CustomerID)
Then create a record selection formula:
{Orders.OrderDate} = {%datum}
{%datum} is the sql expression
When you run the report, you will see only the last order for each customer -
How to get only the latest record in a folder
Hi all,
We have an OA SIT that is not a "standard" SIT in that it does not have the traditional Begin and End date. It only has an Effective date. Is there some way I can filter this table to only give me the latest record in the series? I know how to do this in SQL, but don't see how it would be possible in the EUL.
We're trying to avoid creating database views, but at this point, I'm thinking it may be the easiest way to address this. Any other suggestions?
Thanks in advance,
JewellJewell.
Of course I'm not going to mention that I have no idea what a 'standard' SIT is compared to your basic 'non-standard' SIT ... and I have to watch my spelling of such ... but however ...
As you're most likely aware, in SQL you would get all the 'standard' SIT records first by going through the table. Then you'd go back through them all and find the most recent one.
Because of this 2 table pass, I agree that just putting the SQL code in a custom folder (as you're not using views) would make the most sense.
Russ -
Reg: How to capture the Excise Invoice with respect to Inbound delivery
Hi All,
Please give the process follow for capturing the excise invoice with respect to inbound delivery.
Thanks & Regards
SivaHi Siva,
Please check this link
CIN with Example..?
Regards,
Bijoy Kumar -
I have a use case where I need to use different download directories with different firefox profiles.I need to use this profiles in multiple linux machines.
I need to have a relative path to my download directory with respect to the profile folder.
Ex: I have a selenium test which opens a website and downloads it to my machine.I want this downloaded file to go into some specific folder relative to this profile folder.How do I do this??That is not a practically empty xinitrc - that file only needs one line: exec WM. Other things are entirely optional, and some of them very useful, but I'd encourage you to stick with the simplest xinitrc that will do what you require.
Is slim involved? Probably. That is the source of many problems. But to start narrowing this down, I have 3 suggestions:
1) temporarily (at least) change your inittab to default to runlevel 3 ... actually, is it currently set to 5 or 3? if it is currently 3 that would explain why slim doesn't start.
2) at a tty in runlevel 3 use "xinit" instead of "startx". Startx is fine most of the time, but it is essentially just a complex wrapper for xinit. That complexity can often iadd useful functionality, but it *always* makes troubleshooting more difficult. So for now just use a vanilla 'xinit'.
3) remove dbus-launch from your exec line in xinitrc. This is done by console-kit so it is redundant and potentially problematic. Further BOTH of these are taken care of by slim, so I'd even suggest getting both a jump start on being ready for slim and simplifying troubleshooting by removing both of them. Just make that line "exec openbox-session"
Edit: adding one more:
4) temporarily switch out openbox-session for openbox. I suspect the reason feh's setting of the background is getting overridden is due to a script or setting in openbox's autostart settings - many of these are only invoked when "openbox-session" is called, while "openbox" starts *just* the window manager itself.
Last edited by Trilby (2012-10-03 17:30:36) -
Continually get a message saying "We are experiencing technical difficulties, please try later" when trying to set up allowances. Not very helpful. Any ideas. I am running the latest itunes with Windows 7 Professional.
Not a solution yet, but received the following from one of the tech people I've been e-mailing back & forth with.
"I'm sorry that you have been unable to submit your podcast. The podcast submission form is currently offline. When trying to submit the podcast you will receive this message "We are Currently Experienced Technical Difficulties". Once the issue has been resolved, I would be glad to inform you.
Apple is currently working toward a resolution for the issue you have reported. You will receive an email after the matter has been investigated and further information is available."
Who knows, maybe the problem isn't with my feed after all. -
How to get latest record on top of the result list
Hi Gurus,
How to get latest record on top of the result list when you open the record.
saved data method in BT120H_CPL of OverView page and result list in ICCMP_INBOX.
Regards,
RaviHi
Try sort descending by on fileld "changed at ".
manipulate the sort depends on your requirement
Regards
Logu -
I have added 2 new email accounts to my Imac. How do I get them to appear on my macbook pro and my iPhone. The computers are with maverick and the iPhone has the latest iOS 7.0.3. Thanks
Connect the device to the computer and iTunes and follow the instructions on this support document. http://support.apple.com/kb/HT1808
-
Which option do I have to select If I buy the latest iPad with cellular feature for international use? If I choose verizon can I just change the sim card and insert one from another country?
I would guess you need the A1460 model
see here
http://www.apple.com/ipad/LTE/
Maybe you are looking for
-
why did upgrading my software to snow leopard cause my 'repair disk permissions' to endlessly fail when it never failed once before? by the way i heard all the debate of how repairing disk permissions is or is not important to do. at this point i'm n
-
Cannot open Excel files on Windows share and ONLY Excel files
I'm browsing a Windows share and for whatever reason it will not let me open Excel files directly from the network location. If I view the Coverflow, I can see a a preview of the actual file as well as copy it to the desktop and open it. I receive an
-
Lots of Inactive perl sessions in Oracle 10g r2 on Debian Linux 64 bit
Hi, There are lots of Inactive perl session in Oracle 10g release 2 10.2.0.3.0 on Debian Linux 64 bit, is it normal ps aux|grep oracle is showing following in processes of perl /home/u01/app/oracle/product/10.2.0/database1/perl/bin/perl /home/u01/app
-
Miss,novice besoin d'aide .
bonsoir , j'ai acheter un iphone il y a 10jours, et j'aimerai me fabriquer une liste de lecture mais non pas pour les audio mais pour les vidéos. exmple ,commercial , une autre italien, slow ,etc. j'ai bien chercher sur les differents forums, mais je
-
Firefox not installing, extraction runs then nothing happens.
When I try to upgrade to Firefox 4 the little extracting window pops up for about 3 seconds, disappears then nothing happens. I have tried running it as admin, disabling my real-time scanning and firewall, uninstalling Firefox, but nothing works. I a