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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:42:04+00:00 2026-05-19T17:42:04+00:00

I have two tables ‘Receipt Table:’ and ‘Person Table:’ I need to find the

  • 0

I have two tables ‘Receipt Table:’ and ‘Person Table:’
I need to find the result set for these values
SUM amount, MAXIMUM amt paid as of today, MAXIMUM amt paid_DATE as of today,
RECENT amt paid as of today, RECENT amt paid_DATE as of today.

Here is the Tabluler format below.

RECEIPT TABLE:

ReceiptID   Receipt_Date    AmountPaid  PersonID
R001    1/1/2011    $50     P003
R002    1/2/2011    $20.20  P001
R003    1/2/2011    $35     P005
R004    1/4/2011    $17     P002
R005    1/10/2011   $89.20  P003
R006    1/11/2011   $10     P001
R007    1/11/2011   $9.15   P007
R008    1/12/2011   $5.45   P002
R009    1/20/2011   $65     P006
R010    1/23/2011   $20     P004
R011    1/29/2011   $10     P003

PERSON TABLE:

PersonID    PersonName
P001    A_person
P002    B_person
P003    C_person
P004    D_person
P005    E_person
P006    F_person
P007    G_person
P008    H_person

OUTPUT RESULT:

PersonID    PersonName  Sum(Amtpaid)    RECENT(AmountPaid)  RECENT(Amtpaid_ReceiptDate) Max (Amt Receipt_paid as of today)  Max (amt receipt paid Date as of today)
P001    A_Person    $30.20  $10     1/11/2011   $20.20  1/2/2011
P002    B_person    $22.45  $5.45   1/12/2011   $17     1/4/2011
P003    C_person    $149.20     $10     1/29/2011   $89.20  1/10/2011
P004    D_person    $20     $20     1/23/2011   $20     1/23/2011
P005    E_person    $35     $35     1/2/2011    $35     1/2/2011
P006    F_person    $65     $65     1/20/2011   $65     1/20/2011
P007    G_person    $9.15   $9.15   1/11/2011   $9.15   1/11/2011
  • 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-19T17:42:05+00:00Added an answer on May 19, 2026 at 5:42 pm

    I’m not on a computer where I can test this code, but maybe you can try this:

    ;WITH Receipts AS
    (
        SELECT  *, 
                SUM(AmountPaid) OVER(PARTITION BY PersonID) SumAmount, 
                MAX(AmountPaid) OVER(PARTITION BY PersonID) MaxAmount,
                MAX(Receipt_Date) OVER(PARTITION BY PersonID) RecentPaidDate
        FROM ReceiptTable
    )
    
    SELECT  P.PersonId, P.PersonName, 
            MIN(SumAmount) SumAmount,
            MIN(CASE WHEN Receipt_Date = RecentPaidDate THEN AmountPaid END) RecentAmountPaid,
            MIN(RecentPaidDate) RecentPaidDate,
            MIN(MaxAmount) MaxAmount,
            MIN(CASE WHEN AmountPaid = MaxAmount THEN Receipt_Date END) MaxAmountReceiptDate
    FROM PersonTable P
    JOIN Receipts R
    ON R.PersonId = P.PersonID
    GROUP BY P.PersonId, P.PersonName
    

    Anyway, if you use the code before, you should be aware that it returns the MIN ReceiptDate in case that the MaxAmountPaid is repeated (meaning that it has 2 records that are the same amount and the MaxAmountPaid).

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

Sidebar

Related Questions

I have two tables in my database. A person and a coach table. The
I have two tables: table a ida valuea 1 a 2 b 3 c
I have two tables one with ID and NAME table 1 ID | NAME
I have two tables user table user_id | name | 1 | peter |
I have two tables, a user table and a application table: User id username
I have two tables connected with one to many relationship. Parent Table is a
I have two tables with this structure: Table one: ID Description Table two: ID
I have two tables. Table Emp id name 1 Ajay 2 Amol 3 Sanjay
I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have two tables. One table contains information about Assets, another Table about their

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.