Query to find the latest two transactions for each Group
Hi All,
Consider the following sets of records in a table test.
Group---Tran_Dt---SlNo
c1 10/10/2003 1
c1 10/10/2003 2
c1 10/10/2003 3
c1 11/10/2003 1
c2 10/10/2003 1
c2 10/10/2003 2
c2 11/10/2003 1
c2 11/10/2003 2
c2 11/10/2003 3
c3 10/10/2003 1
c3 10/10/2003 2
c3 10/10/2003 3
I want to list out the latest two transactions for each group irrespective of the slno and trans_dt as below:
group tran_dt SlNo
c1 11/10/2003 1
c1 10/10/2003 3
c2 11/10/2003 3
c2 11/10/2003 2
c3 10/10/2003 3
c3 10/10/2003 2
Any help on this would be appreciated.
Thanks
Walter Nicholas T
Hi Walter,
Please try following query.
select Group,tran_dt,sino from
select Group,tran_dt,sino,(DENSE_RANK()OVER (PARTITION BY Group ORDER BY tran_dt desc,sino desc)) rank from test
) where rank between 1 and 2
Thanks,
Samir
Similar Messages
-
Were do i find the latest up dates for the 3g phone
were do i find the latest up dates for the 3g phone
On iTunes when you connect your iPhone. The latest version for the 3g is 4.2.1. What version do you have on your iPhone?
-
I need a query that selects the amount of records for each day in a table.
I need a query that selects the amount of records for each
day in a table.
Eg the result would be:
date 1 14
date 2 3
etc
Any ideas?sorted:
SELECT count([commentID]),convert(varchar, dateAdded, 112)
FROM COMMENTSgroup by convert(varchar, dateAdded,
112) -
Need to find the latest security update for firefox browser
Due to PCI SOX compliance i need Firefox should be updated with latest security updates.
Please let me know the way from where i can get the latest security update for different version of Firefox.Hello,
If you update Firefox and its plugins to the last versions you will have the last security updates:
*[http://www.mozilla.org/en-US/firefox/new/ Firefox]
*[http://www.mozilla.org/en-US/plugincheck/ Check Plugins] -
Where can I find the latest security hotfix for CF 9.0.2?
ZDNet announces there is a security hotfix for ColdFusion but provides no link to where I can read about it or download it. I go to the Adobe site and look for it by browsing and searching and can't find it. It's been hidden well.
Maybe the ZDNet announcement was made prior to Adobe updating their website? Or maybe I just can't find what is obvious for others.Adobe published it yesterday, you just have to know where to look: http://helpx.adobe.com/security.html is always updated with the latest from the Adobe Security team. More specifically you are looking for this: http://helpx.adobe.com/security/products/coldfusion/apsb14-23.html
Pete Freitag
Foundeo Inc. - Makers of HackMyCF -
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 meHi,
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 -
Query to retrieve latest five transactions for each account
hi,
I have a table containing transactions of all account holders (this table contains thousands of records). My requirement is to retrieve recent five transactions from the table for all the account holders. Can anyone help me to retrieve the required data.
Note: Each account holder may have more than one account e.g. savings account, current account etc.
Regards,
N MadhavanHi,
try something like
select * from (select row_number() over (partition by holders order by transaction_date desc) r, t.* from t) where r<6;
HTH
Laurent Schneider
OCM DBA -
Query to find the top ranked student in each class ?? table given
i/p table:
studentid classid marks
1 1 400
2 1 500
3 2 600
4 2 700
5 3 800
6 3 900
o/p table :
studentid classid marks
2 1 500
4 2 700
6 3 900You dump your homework in a forum of volunteers without even trying to resolve it, and now you start flaming in your very first thread?
Please find assistance elsewhere, where they are more tolerant to the lazy-ones.
Sybrand Bakker
Senior Oracle DBA -
Need to find the dependent object details for an object.
Hi,
Is there any query to find the dependent object details for any object. Like if mview is built on a table, then i should be able to find the table name with out checking code of the mview. Thanks in-advance for your support. similar way for view and functions or procedures etc...
Regards
DBA.Hi all,
Thanks a lot for your inputs. seems i have not given full details in my post. I need to have a SQL Query to find the dependent object details not DDL.
if i give a metriealized view name, i should get the base table names directly not DDLs...
if i give index name i should get its corresponding table name(off course i got this already)...
if i give a function name, i should get all the tables which are being in the function...etc...
i am looking for a script which will cover all the aspects.....i hope i have given now enough information for this....
Regards
DBA. -
Need help on how to identify the latest timestamp ran for the WorkBooks
I know some tables to identify the workbooks when they are created.But this tables are not updating If we ran the workbook today.
for example, : if we created workbook & saved on 05/25/2009 or opening old WB.After that if we ran same workbook on 05/26/2009 then system has to update the latest timestamp as last ran.but iam unable to find this timestamps for workbooks.
WB are maitained in RSDDSTAT.here i can able to find when it was last changed but not the latest timestamps.Our requirement to find the latest timestamp ran for the WorkBooks from last one year, which are using.
below are the tables to identify when the workbook was created and other details:
RSRWBINDEX List of binary large objects (Excel workbooks)
RSRWBINDEXT Titles of binary objects (Excel workbooks)
RSRWBSTORE Storage for binary large objects (Excel workbooks)
RSRWBTEMPLATE Assignment of Excel workbooks as personal templates
RSRWORKBOOK Where-used list for reports in workbooks
Thanks in advance
MaheshAny Updates,
I got one more table to identify WB,
/BI0/PTCTWORKBK - Master Data (Time-Ind.): Characteristic Workbook
Still unable to find Last run timestamps for workbooks
Mahesh. -
How to handle goup sub total for each group in oracle query ?
hi,
i want to handle one complex thing in oracle query.
i have a grouping in my oracle query.
i want to do sub total for each group in query and after that i want to subtract one group sub total from previous group subtotal ?
so how can i handle this in oracle query ?
any help is greatly appreciated.
thanks.Hello
Interesting requirement.
I wonder why are you not using these calculation during the display time. If it is acceptable then you can try using the custom formula with the running total combination in crystral report to achieve to get the required results.
Best regards
Ali Hadi -
Display last two rows for every group
Hi,
I want to display only last 2 rows for every group.
My table look like
ACN DATE COST APPL
A6ERA 14-JUN 150 B777
A6ERA 14-JUN 180 B787
A6ERA 15-JUN 120 B677
A6ERA 14-JUN 155 B777
A6ERB 13-JUN 166 A777
A6ERB 14-JUN 157 B777
A6ERB 11-JUN 159 B787
A6ERC 14-JUN 099 B777
A6ERC 11-JUN 102 B788
In the above table, I want to display only the last two rows group by ACN
Like the below table
ACN DATE COST APPL
A6ERA 15-JUN 120 B677
A6ERA 14-JUN 155 B777
A6ERB 14-JUN 157 B777
A6ERB 11-JUN 159 B787
A6ERC 14-JUN 099 B777
A6ERC 11-JUN 102 B788
Please replyNihar
To get the first two rows from each group, you could do this:
Use the ROW_NUMBER() analytic function (see http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions137.htm#i86310)
Now, your question isn't clear what you mean by "last" two rows. Last in what order? Whatever it is, you can use the ORDER BY part of the ROW_NUMBER() function to specify the ordering, and reverse it using DESC - for example:
select acn, adate, cost, appl from (
select acn, adate, cost, appl,
row_number() over (partition by acn order by adate desc) as rn
from acntab
where rn <= 2
order by acn, rnHTH
Regards Nigel -
Last() not returning correct value within for-each-group
I've found inconsistent results between JDeveloper and SOA Suite using the xslt 2.0 for-each-group construct.
<xsl:for-each-group select="Po/PoLine" group-by="itemId">
<xsl:if test="position()=1">
<GroupCount>
<xsl:value-of select="last()"/>
</GroupCount>
</xsl:if>
</xsl:for-each-group>
What I expect is the function last() to give me the number of groups which is the unique number of itemIds.
In JDeveloper 10.1.3.4, testing this construct gives me what I expect.
At run-time (deployed to 10.1.3.3 SOA Suite), the value returned is the total number of records, not the number of groups.
For example, given the following XML
<Po>
<PoLine>
<itemId><strong>001</strong></itemId>
<description>Hammer</description>
<quantity>10</quantity>
</PoLine>
<PoLine>
<itemId><strong>001</strong></itemId>
<description>Hammer</description>
<quantity>10</quantity>
</PoLine>
<PoLine>
<itemId><strong>002</strong></itemId>
<description>Nail</description>
<quantity>10</quantity>
</PoLine>
</Po>
Grouping by <strong>itemId</strong>, last() should return 2 as there are two groups (001 and 002). JDeveloper does this.
When deployed to SOA Suite, last() returns 3.
Any ideas?Hi,
if JDeveloper is doing the right thing then this issue should be reported to the SOA Suite forum or BPEL BPEL , what do you think ?
Frank -
Top N for each grouping?
Is there a way to show in OBIEE the Top N results for each group?
I want to show the top 10 amounts for each region in my table. If using a Top N filter, it returns the Top N overall results. I tried creating a pivot table and using 'Region' as the section separator, but got the same results. It's only returning 10 amounts total, and I want to see 10 amounts for each region.
KevinYep,
Use the by statement:
TOPN("F1 Revenue"."1-01 Revenue (Sum All)", 10 by "D2 Market"."M01 Market")
regards
John
http://obiee101.blogspot.com/ -
Query to retrieve the number of transactions done in every 1 hour for last
Hi,
Could anyone help in writing a query to retrieve the number of transactions done in every 1 hour for last month.
Case:
I/P
Cases Timestamp1
case1 01-01-2008 00:00:01
case2 01-01-2008 00:01:01
case3 01-01-2008 01:00:01
case1 01-01-2008 01:02:01
case4 01-01-2008 01:10:01
case5 02-01-2008 02:00:01
case6 02-01-2008 02:10:01
case7 02-01-2008 23:00:01
case.. 31-01-2008 24:00:00
O/P
from time to_time cases
01-01-2008 00:00:00 01-01-2008 01:00:00 2
01-01-2008 01:00:01 01-01-2008 02:00:00 3
etc
Any help really appreciatedWe can do this using analytical functions
Following is what I did:
create table timestamp1 (ts date)
select *from timestamp1
30/10/2008 15:41:13
30/10/2008 15:41:05
30/10/2008 15:40:03
30/10/2008 14:58:26
30/10/2008 14:29:45
30/10/2008 13:17:48
30/10/2008 08:29:50
30/10/2008 06:05:51
30/10/2008 03:41:52
30/10/2008 02:29:54
select distinct to_char(ts,'hh24') frmhrs,
to_char(ts,'hh24')+1 tohrs, count(ts) OVER (order by to_number(to_char(ts,'hh24')) RANGE (1/24) PRECEDING )
from timestamp1
where trunc(ts)=trunc(sysdate) -- I added this just to make sure I get for today's data
order by frmhrs
FRMHRS TOHRS CNT
02 3 1
03 4 1
06 7 1
08 9 1
13 14 1
14 15 2
15 16 3
You can customizeas per ur need.
Maybe you are looking for
-
Unknown error purchasing from Apps store
When trying to purchase anything from the Apps store, I get an 'Unknown Error' once I click on the buy button. I have no problem with iTunes, just tha App store. Any ideas? Jim
-
I have two wlc 5508 in HA with image version 7.4.110. These two WLC are connected on two 6509 Catalyst Switch VSS system. On the WLC the LAG are enabled for the connection to the VSS. When i am trying to add the WLC to PI 2 once is succsessful. The
-
I installed J2EE on Windows NT. I am getting the following exceptions when I started J2EE Server.... 1. java.lang.NullPointerException at com.sun.enterprise.server.J2EEServer..... 2. RuntimeException: Unable to create ORB. Possible causes include TCP
-
Javac missing after install on RedHat 8
Hello, I'm trying to install j2sdk-1_4_2_11-linux-i586-rpm.bin on our Red Hat server. I followed the instructions and it seems as if the RPM does install. However when I change into the directory /TheInstallDir/linux/java/jre1.4.2/bin there is no jav
-
Adding navigation items to view controllers in interface builder - pwnd me
I am perplexed by Interface builder. I had SDK version 2.x (can't recall now) and just upgraded to the newest 3.1 and now things do not work the same. So that I could have a custom navigation item applied to my view controller, I have followed the in