1. Get rid of all advertisements and get unlimited access to documents by upgrading to Premium Membership. Upgrade to Premium Now and also get a Premium Badge!

Sql to retrieve last 3 records if they match a certain criteria

Discussion in 'SQL PL/SQL' started by ribena1980, Jun 28, 2016.

  1. ribena1980

    ribena1980 Starter

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    10
    Location:
    Dublin
    Hi There,

    Im looking for the following

    TBL_TRANSACTION
    (
    ACCOUNT ID
    TRANSACTION_DETAILS
    TRANSACTION_DATE
    TRANSACTION_TYPE
    )

    ACC_ID TRANS_DTLS TRANS_DATE TRANS_TYPE

    1001 Petrol 01-Sept-2015 Cash
    1001 Petrol 01-July-2015 Cash
    1001 Fruit 01-May-2015 Cash
    1001 Biscuits 01-Feb-2015 Cash

    1002 Cereal 01-Sept-2015 Cash
    1002 Soft Drinks 01-July-2015 Card
    1002 Water 01-May-2015 Cash
    1002 Water 01-Feb-2015 Card

    1003 Milk 01-Sept-2015 Card
    1003 Petrol 01-July-2015 Cash
    1003 Cereal 01-May-2015 Cash
    1003 Biscuits 01-Feb-2015 Cash


    Basically, I want to be able to pull back the records of the account IF the last 3 transactions have ALL been paid for by Cash.

    Regarding the data above, Account 1001 would be returned as the last 3 transactions have all been Cash, where are 1002 and 1003 would not as atleast 1 of the last 3 transactions are card payments.

    Any help gratefully appreciated.
     
  2. zargon

    zargon Community Moderator Forum Guru

    Messages:
    2,347
    Likes Received:
    348
    Trophy Points:
    1,430
    Location:
    Aurora, CO
    What have you written to solve this problem? We are not here to do your work for you but to help you get it done.

    Post the query you have that isn't working and we can help fix it.