Home » SQL & PL/SQL » SQL & PL/SQL » Finding the last trx (by date) per customer, per transaction type (10g, HP-UX)
Finding the last trx (by date) per customer, per transaction type [message #614081] Thu, 15 May 2014 23:46 Go to next message
HugeOu
Messages: 2
Registered: May 2014
Location: South Africa
Junior Member
Hi all

Newbie here.

I need to run a query where I can find the latest balance per Customer per Transaction Type. My table structure looks as follows:

- Transaction Type
- Transaction Date (End_of_Call)
- Client ID
- Available Balance (for that particular Transaction Type)

Basically, a client can purchase "airtime bundles" which he can than consume from in different transactions (the transaction type). An example of the data would look as follows:
TRANSACTION_TYPE_UID	END_OF_CALL	        SUBSCRIBER_UID	        BALANCE
79001	                2014/04/26 13:47	606094135		2147483648
79001	                2014/04/26 13:51	606094135		4294967296
79001	                2014/04/30 16:53	606096826		104857600
79001	                2014/04/22 12:49	606104927		524288000
79013	                2014/04/10 14:59	798190099		61200812
79013	                2014/04/22 14:43	818888488		1888107861


As you can see from the first 2 rows, that particular Subscriber has 2 entries in the table, and I need a script where the output would be the Balance as at 2014/04/26 13:51, which is the last transaction for that subscriber for that transaction type.

I would greatly appreciate it if anyone can assist me with coming up with a query where I can get the latest value, per Subscriber, per Transaction Type

Many thanks,
Hugo


[EDITED by LF: applied [code] tags to preserve formatting]

[Updated on: Thu, 15 May 2014 23:53] by Moderator

Report message to a moderator

Re: Finding the last trx (by date) per customer, per transaction type [message #614082 is a reply to message #614081] Thu, 15 May 2014 23:52 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and please read http://www.orafaq.com/forum/t/174502/102589/
Re: Finding the last trx (by date) per customer, per transaction type [message #614083 is a reply to message #614082] Fri, 16 May 2014 00:03 Go to previous messageGo to next message
Littlefoot
Messages: 21825
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
That would be something like
  SELECT t.transaction_type_uid,
         t.end_of_call,
         t.subscriber_uid,
         t.balance
    FROM test t
   WHERE t.end_of_call =
            (SELECT MAX (t1.end_of_call)                                     --> latest value
               FROM test t1
              WHERE t1.transaction_type_uid = t.transaction_type_uid         --> per transaction type
                    AND t1.subscriber_uid = t.subscriber_uid)                --> per subscriber
ORDER BY t.transaction_type_uid, t.subscriber_uid, t.end_of_call;
icon14.gif  Re: Finding the last trx (by date) per customer, per transaction type [message #614085 is a reply to message #614083] Fri, 16 May 2014 00:20 Go to previous message
HugeOu
Messages: 2
Registered: May 2014
Location: South Africa
Junior Member
Thanks Littlefoot - worked like a dream! You saved me hours, if not days - I was at the point of playing with the data in Excel, which is always my last resort.

Cheers,
Hugo

[Updated on: Fri, 16 May 2014 00:20]

Report message to a moderator

Previous Topic: insert with different values
Next Topic: Memory use by Hash join in Oracle 11g
Goto Forum:
  


Current Time: Sun Aug 03 04:32:41 CDT 2025