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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:41:35+00:00 2026-06-15T08:41:35+00:00

I have this SQL Queries, SELECT PaymentID, CustomerID, PaymentDate, Amount, Balance, Credit FROM Payment

  • 0

I have this SQL Queries,

SELECT PaymentID, CustomerID, PaymentDate, Amount, Balance, Credit 
FROM Payment 
WHERE (PaymentDate = '2012-11-03')

I also like to print previous Balance and Credit form last transaction of the customer.
This is my try.

SELECT DISTINCT TOP 1 Balance, Credit, PaymentID 
FROM Payment 
WHERE CustomerID = '??' AND PaymentID < '??'
ORDER BY PaymentID DESC

As you can see this does nothing as Queries are not liked.
I think I have I have to use T-SQL or UNION but have no idea How to implement it.

This kind of Output I am trying to achieve.

enter image description here

Payment Table

PaymentID   int 
CustomerID  varchar(50)
PaymentDate date
Amount  decimal(18, 2)
Balance     decimal(18, 2)
Credit  decimal(18, 2)

Note:

This is for all the customers not only for single customer, it’s like a sale Report.
There are can be more than one payment per customer in a day.

  • 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-15T08:41:36+00:00Added an answer on June 15, 2026 at 8:41 am

    This might get you started

    SELECT P1.paymentID, P1.CustomerID, P1.PaymentDate, max(PP.paymentID)
    FROM Payment P1 
    Join Payment PP 
      on PP.paymentID < P1.paymentID 
     and PP.CustomerID = P1.CustomerID
     and P1.PaymentDate = '2012-11-03'
    GroupBy P1.paymentID, P1.CustomerID, P1.PaymentDate
    
    
    not test but I think this will pull in the other data
    
    select PC.*, PL.PaymentDate,  PL.Amount,  PL.Balance,  PL.Credit 
    from 
    (SELECT P1.paymentID, P1.CustomerID, P1.PaymentDate, max(PP.paymentID) as PriorPID
    FROM Payment P1 
    Join Payment PP 
      on PP.paymentID < P1.paymentID 
     and PP.CustomerID = P1.CustomerID
     and P1.PaymentDate = '2012-11-03'
    GroupBy P1.paymentID, P1.CustomerID, P1.PaymentDate) as PC 
    join Payment PL 
      on PL.paymentID = PC.PriorPID 
     and PL.CustomerID = PC.CustomerID 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a lot of SQL queries like this: SELECT o.Id, o.attrib1, o.attrib2 FROM
I have two dynamic sql queries like this @sql = 'select productname,year from products'
i have this sql query select * from table where name like ? but
I have this SQL statement: SELECT * FROM history WHERE (fk_person = 2119) AND
I have this SQL query from the logs select content = 5%id%201=1 from pages
I have two sql queries: $query0=mysql_query(SELECT caseNumber FROM shipped_data WHERE palette='P0' AND shipInvoiceNumber='2011/229'); $query1=mysql_query(SELECT
I have this postgres sql query: select * from stats where athlete_id = 5
I need to implement cache for SQL queries. Say we have SELECT id,aa,bb FROM
I have two sql queries select * from table1 ORDER BY column1 Select top
Are ordinary sql queries different from MS Access 2007 queries? I have this simple

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.