Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6527867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:28:54+00:00 2026-05-25T09:28:54+00:00

We have a loyalty card database at my company. The card system is served

  • 0

We have a loyalty card database at my company. The card system is served by two types of terminals nationwide. The trouble is, the two terminals count the current point balance differently.

I want to make a query that first finds the last row of a single user’s transaction list by date, then checks the ID of the terminal, and based on what the ID is, returns the card balance from the same row.

The two types of terminals can be expressed like this:

terminal_id LIKE 'AGHUPR9%'
terminal_id LIKE 'AGHUPR7%'

The AGHUPR9% ones get the balance simply from a column called card_balance.
The AGHUPR7% ones need to sum the card_balance and the total_points columns to get the current balance.

I wrote the main parts of the query but I’m not familiar enough with ORACLE so I don’t know how to combine them syntactically. This is what I’d appreciate your help with. Below is what I came up with, with comments where I’m not sure about the code needed.

SELECT *
FROM
(SELECT terminal_id
FROM ag_tranzakcio
WHERE cardnumber = '9348722610095185'
ORDER BY tran_date DESC)
WHERE ROWNUM = 1

In case the above statement returns a terminal_id starting with AGHUPR9, do this:

SELECT *
FROM
(SELECT card_balance
FROM ag_tranzakcio
WHERE cardnumber = '9348722610095185'
ORDER BY tran_date DESC)
WHERE ROWNUM = 1

In case the first statement returns a terminal_id starting with AGHUPR7, do this instead:

SELECT *
FROM
(SELECT card_balance+total_points
FROM ag_tranzakcio
WHERE cardnumber = '9348722610095185'
ORDER BY tran_date DESC)
WHERE ROWNUM = 1

How do I combine them into a working query? I’m trying to use CASE with little success.

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T09:28:55+00:00Added an answer on May 25, 2026 at 9:28 am

    Simply use a CASE statement.

    SELECT *
    FROM
    (SELECT 
       CASE 
         WHEN terminal_id LIKE 'AGHUPR9%' THEN card_balance 
         ELSE card_balance+total_points 
       END AS card_balance
    FROM ag_tranzakcio
    WHERE cardnumber = '9348722610095185'
    ORDER BY tran_date DESC)
    WHERE ROWNUM = 1
    

    This will use card_balance when the terminal_id starts with “AGHUPR9”, otherwise it’ll use card_balance+total_points, returning the answer in a column named ‘card_balance’ in either case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a database of loyalty card holders. I'm trying to write a simple
I have a table with data from the database, I would like it to
Have a simple iPhone app with a single UIViewController and two Views in one
Have a MySQL database table with 2 columns: id, url The url column has
I have a method in my windows service as follows: System.IO.File.Copy(path, ConfigurationManager.AppSettings[BulkInsertGiftRegisterCreatorDirectory] + System.IO.Path.GetFileName(path));
I am querying the database for different values of prizes for an online loyalty
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have done quite a bit of searching for a guide (of any substance) for
Have deployed numerous report parts which reference the same view however one of them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.