Get the latest date record in Query
Hi, Expert:
Please help on this:
The requirement is to get the the latest date record in Query. For example:
Data in provider:
Plant date amount
A01 2007/04/08 30
A01 2007/06/09 70
A01 2007/12/08 30
we only want the query display:
A01 2007/12/08 30
I have tried exception aggregation, but it does not work. Any ideas are highly appreciated.
Or you can model the date as a key figure after 0date_kyf and set aggregation to max, you'll get something like
select plant, amount, max(date) from ... group by plant, amount
used it for inventory reporting (materials and their last movement date, days from the last movement etc.) and worked well.
Similar Messages
-
Hello,
I have simple question ....i dont know why i m brain dead today...
I m trying to get the latest date for the each id
with test_data as(
select '001'id, 'xyz'name, '1/1/2009'start_date from dual union all
select '001', 'abc', '1/2/2099' from dual union all
select '001', 'def', '1/3/2009' from dual union all
select '001', 'ghi', '1/4/2009' from dual union all
select '001', 'jkl', '1/5/2009' from dual
The output i m looking for just one record with latest date
with result as
select '001', 'jkl', '1/5/2009' from dual
i tried this
select id,name, greatest(start_date) from test_data
group by id,name,start_date
It gives me output ...which i m not lookg for
with t as
select '001', 'abc', '1/3/2009' from dual union all
select '001', 'ghi', '1/4/2009' from dual union all
select '001', 'jkl', '1/5/2009' from dual
)select * from t
I was wondering if we have any function's in oracle PL/SQL to do these kind of stuff's
Any suggestions is greatly appriciated!! Thank you sio much!!
Edited by: user642297 on Mar 12, 2010 12:21 PMSQL> with test_data as(
2 select '001'id, 'xyz'name, '1/1/2009'start_date from dual union all
3 select '001', 'abc', '1/2/2099' from dual union all
4 select '001', 'def', '1/3/2009' from dual union all
5 select '001', 'ghi', '1/4/2009' from dual union all
6 select '001', 'jkl', '1/5/2009' from dual union all
7 select '002', 'ghi', '1/4/2009' from dual
8 )
9 select id, max(start_date), max(name) keep (dense_rank first order by start_date desc)
10 from test_data
11 group by id;
ID MAX(STAR MAX
001 1/5/2009 jkl
002 1/4/2009 ghiMax
http://oracleitalia.wordpress.com -
Get the latest date from 2 date columns per row
I have a table that contains following columns:
NAME
DATE1
DATE2
From each row, I want to select the value for name and the latest date of DATE1 or DATE2.
So, if this table contained data below:
NAME DATE1 DATE2
A 01/01/2008 01/01/2009
B 12/01/2008 01/01/2008
C 01/01/2008 12/31/2008
I want a SQL script that returns
A 01/01/2009 (value of DATE2)
B 12/01/2008 (value of DATE1)
C 12/31/2008 (value of DATE2)
Please let me know if you happen to know the SQL command for accomplishing this. Thank you.Use GREATEST function.
Regards.
Vidya -
How to Check the date and get the latest date?
Hi Everyone,
I've an internal table which holding few records which contain date field. How I can check this internal table by getting the record which contain "latest date" only? Kindly advise. Thank you.
eg:
I should only get the record which contain lastest date. (eg: I should picked up Record3)
Table i_test
Field 1 Field 2(date)
Record1 20090322
Record2 20090101
Record3 20090601
Moderator message - Please search before asking and do not ask basic questions - post locked
Edited by: Rob Burbank on Jun 17, 2009 9:21 AMIts easy...sort the internal table using the field i.e. date field in DESCENDING manner
SORT gt_final BY date_field DESCENDING.
Read the first entry of the internal table..it will have what you require
READ gt_final INDEX 1. -
How to get the latest ALV record?
Hi all,
I have create a ALV in my module pool with delete row feature. The module pool is able to display the record into the ALV.
The user needs to delete some of the unwanted records. After that, my program needs to populate the record (after deleted rows), and save it into a customized table.
My question is, how can I get the most up-to-date record from the ALV and assign it into internal table?
Thanks in advance.Hi,
Yes, I am using OOPs ALV
I have included this code into PAI, but how do I get it assigns to a internal table?
data: lv_valid type c,
lv_refresh type c.
call method grid1->check_changed_data
importing
e_valid = lv_valid
changing
c_refresh = lv_refresh.
PBO
data grid1 type ref to cl_gui_alv_grid.
call method grid1->set_table_for_first_display
exporting
i_structure_name = 'ZSTRUCTURE_EXCEL'
it_toolbar_excluding = lt_exclude
is_layout = ls_layout
changing
it_outtab = gt_export2excel.
FYI, my ALV is with delete row feature, the user will delete some of the row and now I need to get the remaining row and assign it to an internal table.
Please help with some sample code. Thanks. -
How to get the child data in MDX query?
I have an MDX query that will return the data for an OLAP report. These report data include the parent_id, child_id and some dimensions data in it. How do I modify the MDX query to have a New member to show a dimension value of the child_id.
The child_is is actually the parent_id on another row. It is the "Pstpd Decision" I want to be included in a new column using the "Appeal Id". Thanks
WITH MEMBER [Measures].[Avg TA Time] AS [Measures].[Turn Around Time]/[Measures].[Number of Request]
SELECT NON EMPTY { [Measures].[Number of Request] } ON COLUMNS,
NON EMPTY { ([Request Date Time].[FY-AP].[Account Period].ALLMEMBERS *
[Request Drugs].[Drug Generic Name].[Drug Generic Name].ALLMEMBERS *
[Dispensary].[Dispensary Hierarchy].[Dispensary].ALLMEMBERS *
[Disease].[Tumour Group Site].[Tumour Group Site].ALLMEMBERS *
[Disease].[Tumour Group Sub Site].[Tumour Group Sub Site].ALLMEMBERS *
[Patient].[Patient Agency ID].[Patient Agency ID].ALLMEMBERS *
[Pstpd Decision].[Decision].[Decision].ALLMEMBERS *
[Request].[Request Id Key].[Request Id Key].ALLMEMBERS *
[Request].[Appeal Id].[Appeal Id].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM ( SELECT ( { [Appeal Yes No].[Status].&[Yes] } ) ON COLUMNS
FROM ( SELECT ( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED) ) ON COLUMNS
FROM [CAP Request])) WHERE ( IIF( STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED).Count = 1, STRTOSET(@RequestDateTimeFiscalYear, CONSTRAINED), [Request Date Time].[Fiscal Year].currentmember ), [Appeal Yes No].[Status].&[Yes] ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
data.
KahluaI got it to work by adding the child_id's "decison' to the fact table as it is alot easier to get that data using Sql Script while creating the fact table and also there is already a "decsion" dimension setup. In the cube I can select the
parent_id's decision and/or child_id's decision. It is working on the report. Thanks.
Kahlua -
How to get the latest Change date and time of a M.O. from View VIAUFKST
Hi All,
I want to get the latest date and time of a M.O. from view
VIAUFKST. I have written the query like this...
SELECT AUFNR
AEDAT " Changed Date
AEZEIT " Changed Time
FROM VIAUFKST
INTO TABLE I_VIAUFKST
WHERE AEDAT >= W_LASTRUN_DATE
ORDER BY AEDAT DESCENDING.
but its not giving me right results... Pls help me out on this or suggest me the right approach to achieve the same...As this is very critical issue...
Advance Thanks and Points Gauranteed...
Suresh> SELECT AUFNR
> AEDAT
> AEZEIT
> FROM VIAUFKST
> INTO TABLE I_VIAUFKST
> WHERE AEDAT >= W_LASTRUN_DATE.
>
> IF NOT I_VIAUFKST[] IS INITIAL.
> SORT I_VIAUFKST BY AEDAT AEZEIT DESCENDING.
> READ TABLE I_VIAUFKST INDEX 1.
> ENDIF.
>
> The above statement is giving me different results...
> such as...
>
> 1. 30/11/2005 19:20:11
> 2. 29/11/2005 22:10:09
> 3. 30/11/2005 20:56:09
> 4. 28/11/2005 23:10:09
>
> by using the above SORT statement i am getting the
> fourth record as the latest, where as it should give
> me the third record....
>
> Please advise,
> Suresh.
Hi Suresh,
The reason why you are getting this result is because the system is interpreting the DESCENDING only for AEZEIT not for both. Change it to
SORT I_VIAUFKST BY AEDAT DESCENDING AEZEIT DESCENDING -
Discoverer: Capturing record with the latest date among others
Hi there,
I would appreciate if anyone can help me in Discoverer10g Report. The report gives me the following results. Let me know if any more info needed.
Example:
Plan Cov St Dt Amt Elec. Dt Name Rt St dt Comm Ann Enrl Cov St Dt
Basic Life 01-JAN-2011 76000.00 11-NOV-2010 Stephanie 01-JAN-2011 2.63 68.40 11-NOV-2010
Basic Life 01-JAN-2011 76000.00 29-OCT-2010 Stephanie 01-JAN-2011 2.63 68.40 29-OCT-2010 (Yes)
Basic Life 01-JAN-2011 177000.00 29-OCT-2010 Shanika 01-JAN-2011 6.13 159.30 29-OCT-2010 (Yes)
Basic Life 01-JAN-2011 214000.00 19-NOV-2010 Nicole 01-JAN-2011 7.41 192.60 19-NOV-2010 (Yes)
Basic Life 01-JAN-2011 214000.00 29-OCT-2010 Nicole 01-JAN-2011 7.41 192.60 29-OCT-2010
What I want to capture is latest date record from available records of the same employee and if there is only one record, I would want that too. In short, the ones which has '(yes)' at the end.
What function can I use to get the desired results.
Thank you!
NNHi Tamir,
I used the the function(for another report which has similar situation) you mentioned but it gives me an error saying-
ORA-01858: a non-numeric character was found where a numeric was expected.
Its is OAB module indeed. some how due to date issue during our Insurance Vendor changes, I get multiple records of the same employees with some blank fields. See the example below.
*4.36 07-AUG-2010 31-DEC-4712 07-AUG-2010 07-AUG-2010 21206*
NULL 07-AUG-2010 31-DEC-4712 07-AUG-2010 21206
3.95 01-JAN-2010 31-DEC-4712 01-JAN-2010 01-JAN-2010 21206
Now out of three I need the one in bold letters. and there are other employees having just one record like
Amt Cov_St_DT Cov_End_Dt Rate_St_Date Rt_Effective Dt EEID
1.45 15-SEP-2010 31-DEC-4712 15-SEP-2010 15-SEP-2010 22777
7.65 01-JAN-2010 31-DEC-4712 01-JAN-2010 01-JAN-2010 21298
so I need the single records as well as latest(date) record of multiple records of one employee.
Let me know if you need more information.
One more thing- is there any way to see the actual query I am running?(not sql Inspector)
Thank you!
797174
p.s Thank you for the earlier reply.
Edited by: 797174 on Dec 21, 2010 2:18 PM -
Different ways to get the last 5 records ordered by date
I have a query no that returns the tickets ordered by moddt, modification date,
I was thinking of adding a select on top, to get the last 5 records of that list the select already generates. An other way was to use that select to create a view,
and get the 5 last records that way. I also though of a possibly impossible cursor with a sequence, but hmm well I consider that not a good solution.
So I'm trying to find a way, using a select, the topmost select which is not completed yet, to get the last 5 records. Maybe I should just try the rownumber thing again or something likewise.
Select * from(
select * from(
Select ticketid, appliecatiecd, categorieid, substr(titel,&,200)||' ...' "titel", klantproriteitid, interneprioriteitid,
(select g.voornaam||' '||g.naam
from gebruiker g
Where g.gebruikerid = t.gebruikerid
And t.applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd))"aangemaakt door",
(select s.statusdefoms "status"
From status s
Where s.statusid = t.statusid
And t.applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd)) "status",
Versieid,
Moddt,
Row_number() over (order by ticketid desc) rn
From ticket t
Where applicatiecd = NVL(:P0_applicatiecd, :F101_applicatiecd) )
Order by moddt)
Where --Hi Floris,
You can also use RANK: http://www.dba-oracle.com/oracle_news/oracle_faq/faq_beg_sql_top_n_rows.htm
Regards Pete -
Finding the record with the latest date
Post Author: sconlon
CA Forum: General
Hi,I am using CR 8 with an Access database which has a table that holds (multiple) sales records for each of our clients. I want to create a report that lists only the latest sale from each client. I am thinking that I first need to group by client and then create a sub-report that prints the necessary details of sales record with the latest date of sale. It's this last bit that I cannot figure out how to do. Can anyone suggest a way of doing this?Many thanks,sconlonPost Author: Jagan
CA Forum: General
Charliy's suggestion if fine, and does require sorting and displaying in the group header/footer according to the sort order. In case it's not clear, when you print in the group header you are using the first record's data; when you print in the group footer you are using the last record's data (first and last within the group that is).
Personally, I'd group on the client have a group selection formula of:
{table.date_field} = maximum({table.date_field}, {table.client_id})
so that there's no date sort required as you'll only get one record per client group - assuming that each record has a unique date of course. I'd probably still suppress the details section and display in the group footer, but it wouldn't matter if you use the details section either.
I believe the benefit with the group selection formula is that any summary formulas, running totals etc. you use would only have the one record per client to work on, rather than including all of the suppressed records too. -
Reg: Getting the latest or last saved data from the table
Hi,
I'm having a table, which is getting updated whenever something is saved.
Now i want to get the latest or last saved details to be displayed or the details of the row with greatest Id.( i.e, the Id. will be greatest for the last saved)
please help me out with code to do this...
Thanks & Regards,
SureshHi Suresh,
This could be done either through the webdynpro or the back end function module itself.
If another field of type date/time is present in the table, u can save the current date and time along with the data in the table, and sort it in descending order of time. so that whenever u refresh the page the latest record is always in the first row,
if u want to do it through webdynpro, u can also sort the table based on the date so that u get the latest record that was saved.
Another solution is that u can maintain a serial number sort of thing the table which helps u identify the latest record
Hope this helps u.
Regards,
Poojith M V -
Is it possible to get the updated table records based on date & time.
Is it possible to get the updated table records based on date & time in oracle.
Thanks in advance.no, actually i am asking update records using 'UPDATE
or DELETE' statement, but not insert statement.
Is it possible?
I think we can do using trigger on table, but problem
is if i am having 20 tables means i have to write 20
trigger. i don't want like this.Of course it's still possible, typically you'll find applications with a column LAST_UPDATE, probably a LAST_UPDATED_BY and so on column. You don't say what your business need is, if you just want a one of query of updates to particular records and have a recent version of Oracle, then flashback query may well help, if you want to record update timestamps you either have to modify the table, or write some code to store your updates in an audit table somewhere.
Niall Litchfield
http://www.orawin.info/ -
Can I get a query to get the output data like 4th column instead of 3rd col
Can I get a query to get the output data like 4th column instead of 3rd column ?
SQL> select emp.deptno, empno, rownum from emp, dept where emp.deptno=dept.deptno;
DEPTNO EMPNO ROWNUM
10 7782 *1* *1*
10 7839 *2* *2*
10 7934 *3* *3*
20 7369 *4* *1*
20 7876 *5* *2*
20 7902 *6* *3*
20 7788 *7* *4*
20 7566 *8* *5*
30 7499 *9* *1*
30 7698 *10* *2*
30 7654 *11* *3*
30 7900 *12* *4*
30 7844 *13* *5*
30 7521 *14* *6*
14 rows selected.SQL> select emp.deptno, emp.empno,
2 row_number() over(order by emp.deptno, emp.empno) rn,
3 row_number() over(partition by emp.deptno order by emp.empno) dept_rn
4 from emp, dept
5 where emp.deptno=dept.deptno
6 order by emp.deptno, emp.empno;
DEPTNO EMPNO RN DEPT_RN
10 7782 1 1
10 7839 2 2
10 7934 3 3
20 7369 4 1
20 7566 5 2
20 7788 6 3
20 7876 7 4
20 7902 8 5
30 7499 9 1
30 7521 10 2
30 7654 11 3
30 7698 12 4
30 7844 13 5
30 7900 14 6
14 rows selected.Regards,
Dima -
Trying to get the top N records from a query.
Hello,
Im trying to get the top N records of a random query. I've been looking for a decent solution for a while now and the 2 solutions I've come across are:
select *
from (select * from qrs_klantgroepen order by code) a
where rownum < 10
ORA-00907: missing right parenthesis
The query works when I remove the order clause from the subquery, but it's mandatory to get the results I need.
The next solution:
select *
from (select code, row_number() over (order by code) from qrs_klantgroepen) a
where rownum < 10
ORA-00923: FROM keyword not found where expected
Apparently the construct used here isn't supported by my oracle version.
I'm using oracle Oracle8 Enterprise Edition Release 8.0.5.2.1.
Is there another way I can achieve the results I want?
Looking forward to your replies.
Frederikit must be nostalgy, but I would try something like
SQL> select * from emp e where 5>(select count(*) from emp where ename<e.ename) order by ename;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 1987-05-23_00:00:00 1100 20
7499 ALLEN SALESMAN 7698 1981-02-20_00:00:00 1600 300 30
7698 BLAKE MANAGER 7839 1981-05-01_00:00:00 2850 30
7782 CLARK MANAGER 7839 1981-06-09_00:00:00 2450 10
7902 FORD ANALYST 7566 1981-12-03_00:00:00 3000 20
SQL> select * from (select * from emp order by ename) where rownum<6;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7876 ADAMS CLERK 7788 1987-05-23_00:00:00 1100 20
7499 ALLEN SALESMAN 7698 1981-02-20_00:00:00 1600 300 30
7698 BLAKE MANAGER 7839 1981-05-01_00:00:00 2850 30
7782 CLARK MANAGER 7839 1981-06-09_00:00:00 2450 10
7902 FORD ANALYST 7566 1981-12-03_00:00:00 3000 20Message was edited by:
Laurent Schneider -
Need Store DB tables to query to get the latest scanned price at register
Need Store DB tables to query to get the latest scanned price at register.
Please provide a sample sql script that will help me do this. I need to have this informatino for several items at a time.
Thanks,
Edited by: user10133807 on Jan 13, 2012 9:22 AM
Edited by: user10133807 on Jan 13, 2012 9:23 AMHi,
You can find multiple items saled price at the register by running below quary
select distinct DC_DY_BSN,ID_ITM_POS,MO_PRN_PRC from TR_LTM_SLS_RTN;
Thanks,
MG
Maybe you are looking for
-
How can I change (or select) what is being being used when I share, as the file cover. When I Share lets say "Master File" i want to select a frame that is used as the file cover. So when its on my desktop I see this image as the file icon.
-
My current email address that is my apple ID is going to be discontinued. I tried to change it to my valid email address but that is my recovery email. Without starting still another email address how can I fix this?
-
LMS 3.1 Backup job Failing
Hello, We have LMS 3.1 installed and the backup is failing with the following message [Tue Feb 8 09:20:26 2011] ERROR(247): E:/Backup_3/backup.LOCK file exists Most probably another backup process is running [Tue Feb 8 09:20:26 2011] Backup faile
-
I'd like to find out how to network my two system (IMAC and PC windows XP) with Airport Extreme 802.11 so to share one hard drive with the other. It's taken me 2 day to get that green light burning stead and network a printer with APE and I'm just wo
-
Search based on UnApproved status in HRMS
Hi All I have search page which shows records based on search that page has one dropdown list which contain many options like Approved,Closed,Rejected,Unapproved,etc when I select Approved status then It shows all records that are approved and when I