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 8119437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:48:12+00:00 2026-06-06T04:48:12+00:00

In Teradata, I need a query to first identify all members in the MEM

  • 0

In Teradata, I need a query to first identify all members in the MEM TABLE that currently have a negative balance, let’s call that CUR_BAL. Then, for all of those members only, sum all transactions from the TRAN TABLE in order by date until the sum of those transactions is equal to the CUR_BAL.

Editing to add a third ADJ table that contains MEM_NBR, ADJ_DT and ADJ_AMT that need to be included in the running total in order to capture all of the records.

I would like the outcome to include the MEM.MEM_NBR, MEM.CUR_BAL, TRAN.TRAN_DATE OR ADJ.ADJ_DT (date associated with the transaction that resulted in the running total to equal CUR_BAL), MEM.LST_UPD_DT. I don’t need to know if the balance is negative as a result of a transaction or adjustment, just the date that it went negative.

Thank you!

  • 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-06-06T04:48:13+00:00Added an answer on June 6, 2026 at 4:48 am
    select
        mem_nbr,
        cur_bal,
        tran_date,
        tran_type
    from (
        select
            a.mem_nbr,
            a.cur_bal,
            b.tran_date,
            b.tran_type,
            a.lst_upd_dt,
            sum(b.tran_amt) over (partition by b.mem_nbr order by b.tran_date rows between unbounded preceding and current row) as cumulative_bal
        from mem a
        inner join (
            select
                mem_nbr,
                tran_date,
                tran_amt,
                'Tran' as tran_type
            from tran
            union all
            select
                mem_nbr,
                adj_date,
                adj_amt,
                'Adj' as tran_type
            from adj
        ) b
        on a.mem_nbr = b.mem_nbr
        where a.cur_bal < 0
        qualify cumulative_bal < 0
    ) z
    qualify rank() over (partition by mem_nbr order by tran_date) = 1
    

    The subquery picks up all instances where the cumulative balance is negative, then the outer query picks up the earliest instance of it. If you want the latest, add desc after tran_date in the final qualify line.

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

Sidebar

Related Questions

I have a table in Teradata that I suspect was changed. Isn't there a
Can anyonen help with Teradata? I want to create a query that is a
I'm trying to make a Teradata SQL query that will return the n -th
We need to access a Teradata database via php application We don't have odbc
I have two tables in a teradata database that look like this accounts account_number
I have a REXX job that needs to read from both Teradata (using BTEQ)
I need to insert the data from an excel sheet into a teradata table.
I need to query data in Tera database from SQLSERVER 2005. I have IP
I have a half dozen views in SQL Server that I need to replicate
In Teradata DB I have source table create set table SRC_TABLE ( Some_Id varchar(2O)

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.